MysqlMysql

  Main Menu

Database to Table Row

This is good to get data from your php array into a table row, without being limited to one db row to one html table row.

 
# from http://www.hvt-automation.nl/yapf/faq.php?cmd=viewitem&itemid=81
# nice little column separator snippet
#
// set the number of columns 
$cols=3;  

// create the HTML table. 
echo "<TABLE>\n<TR>";  

// create the query 
$query = "SELECT * FROM myTable"; 

// run query 
$result = mysql_query($query);  

// initialize the counter 
$x = 0; 

// cycle through the results and place each set in an array 
while ($result_array = mysql_fetch_array($result))  
{ 
  // use the modulus operator to determine if we need to reset the table row 
  if (($x%$cols) == 0) 
  { 
    // reset the table row 
    echo "</TR>\n<TR>";  
  } 

  // output the data 

  echo "<TD>".$result_array['data']."</TD>\n"; 

  // increment the counter 
  $x++;  
} 
// close the table 
echo "</TR></Table>";