Php Programming Code Examples
Php > Look and Feel Code Examples
Multi Column Output
Multi Column Output
<html>
<h1><center>Output to 2 columns</center></h1>
<table border="1" align="center">
<?
//you need this - it tells the data what collumn to go to
$count = 1;
$column = 1;
//db connect and select
$link = mysql_connect( "localhost", "root", "password" );
mysql_select_db( "dbname" );
$result=mysql_query ("select * from table_name");
//loop statement
while ($myrow = mysql_fetch_array ($result))
{
// this is the column 1
if ($column == 1)
{
printf("<tr><td><b>$count</b>%s</td>",$myrow[value]);
}
else{
//this is the column 2
printf("<td><b>$count</b>%s</td></tr>",$myrow[value]);
}
//increment the count
$count += 1;
// this is a modulus operator it gets the remainder of the equation
$column = $count % 2;
}
?>
</table>
</html>