Jump to content

help on display code


MDanz

Recommended Posts

this code allows me to display results in column of 8, then start a new row, then 8 columns etc.

 

what i need is the first cell(first row , first column) to be empty... so the first row only has 7 results.

 

so for a test the first cell would echo "TEST"...  how do i adjust this code to get that?

 

$query_result = mysql_query("SELECT * FROM `table`") or die("Error");;
    
$total = mysql_num_rows($query_result);
$row_count = ceil($total / ;

echo "<table>";

// loop through rows
for($row = 0; $row < $row_count; $row++) {
    
    // output start of row
    echo "<tr>";
    
    // loop through columns
    for($col = 0; $col < 8; $col++) {
        
        // grab next row
        $row_data = mysql_fetch_assoc($query_result);
        
        if($row_data != FALSE) {
            // data in array, output cell contents
            echo "<td>" . $row_data['field'] . "</td>";
        } else {
            // no data left in our array
            // output a blank box to finish table
            echo "<td> </td>";
        }    
    }
    // close row
    echo "</tr>";
}
// close table
echo "</table>";

Link to comment
https://forums.phpfreaks.com/topic/195806-help-on-display-code/
Share on other sites

if ($row == 0 && $col == 0 ) {
  echo "<td>TEST</td>";
} else {

  // grab next row
  $row_data = mysql_fetch_assoc($query_result);
  if ($row_data != FALSE) {
    // data in array, output cell contents
    echo "<td>" . $row_data['field'] . "</td>";
  } else {
    // no data left in our array
    // output a blank box to finish table
    echo "<td> </td>";
  }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.