0

I have 10*10 fixed table that print two for loops. Some images are shown in some given table cell witch match the given row id and column id from admin.

$table .= '<table border="1" cellspacing="0" cellpadding="2" class="banner_table">';
    for($x=1; $x<=10; $x++) {
       $table .= "<tr>";
       for($y=1; $y<=10; $y++) {
           $table .= "<td class='thumbnail'>";

                if (isset($temp[$x][$y])) {
                    $count++;  
                    $table .= "<a target='_blank' href='" . ($temp[$x][$y]['img_url'] ? $temp[$x][$y]['img_url'] : "#") . "'>
                    <img id='imgid' src='admin/small-image/" . $temp[$x][$y]['img_title'] . "' width='20' height='20' /></a>";                   
                }  
           else $table .="&nbsp;";
           $table .= "</td>"; 
        }
        $table .= "</tr>";
   }
   $table .= '</table>';

How should I give index number such as 1,2,2... for the table cell without given row id and column id ? I want to give index no 1 (ROW 1 AND COL1), Index no 2 (ROW1 and COL2) likewise.

Is there any methods to get table cell number from row id and column id?

4

1 回答 1

2
// Index number to row and column:
$index_no = 13; // Number from 1 to 100
$y = floor(($index_no-1)/10)+1;
$x = $index_no-($y-1)*10;

// Row and column to index number:
$x = 4;
$y = 3;
$index_no = ($y-1)*10+$x; // Number from 1 to 100
于 2013-07-09T18:10:48.950 回答