Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Multi Column Output

Code Wizard, 12-30-2006
This is a multi column output from a mysql database so you can output your data into 2 columns, (a little modding = more columns too)
useful because usually you can only print out the data in one column which is tres' dull.


Output to 2 columns




//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("",$myrow[value]);

}
else{
//this is the column 2
printf("",$myrow[value]);

}
//increment the count
$count += 1;
// this is a modulus operator it gets the remainder of the equation
$column = $count % 2;
}

?>
$count%s$count%s
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions