timmah1 Posted December 5, 2006 Share Posted December 5, 2006 This is probably and easy question, but I can't seem to find an easy answer.When I pull info out of the database and put it into a table, how do I get the info to go horizontal instead of vertical?For example, If I want to pull all of the values of $id from the database and list them in a table, instead of listing them straight down, I'd like for the results to show a minimum of 4 values across.See below:[img]http://www.fotobins.com/Picture-2.jpg[/img] Quote Link to comment Share on other sites More sharing options...
Darkness Soul Posted December 5, 2006 Share Posted December 5, 2006 I think you will need to use arrays, never did this before, but maybe..create an array, like $row, into this array, you will record the data, like a table.. $row[0][] = $id, $row[1][] = foo, .. got it?Now you print your table..tr, foreach $row[0] as $x, td $x /td, loop, /trtr, foreach $row[1] as $x, td $x /td, loop, /trSo, you got your table! Test it, and tell me the result? :)D.Soul Quote Link to comment Share on other sites More sharing options...
craygo Posted December 5, 2006 Share Posted December 5, 2006 use this[code]<?php/***** database connection start *****//***** database connection end ******/echo "<table width=300 border=0 align=center>";//set 3 to 4 of you want 4 columns. Set it to 5 if you want 5, etc$numcols = 5; // how many columns to display$numcolsprinted = 0; // no of columns so far// get the results to be displayed$query = "SELECT * FROM table_name ORDER BY id ASC";$mysql_result = mysql_query($query);// get each rowwhile($myrow = mysql_fetch_assoc($mysql_result)){//get data - eg, $id = $myrow['id'];if ($numcolsprinted == $numcols) {print "</tr>\n<tr>\n";$numcolsprinted = 0;}// output row from databaseecho "<td>$id</td>\n";// bump up row counter$numcolsprinted++;} // end while loop$colstobalance = $numcols - $numcolsprinted;for ($i=1; $i<=$colstobalance; $i++) {}print "<TD></TD>\n";?>[/code]Ray Quote Link to comment Share on other sites More sharing options...
timmah1 Posted December 5, 2006 Author Share Posted December 5, 2006 That's perfect!!!Thank you very much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.