spectsteve7 Posted March 18, 2006 Share Posted March 18, 2006 Hi there,I'm new here and I'm looking for a bit of help. I have a table on my page. It's made of 1 row and two columns. I'm looking to query 1 field from my database and display all records with in the database. I'm looking to make as much use of space as possible so I want to have it populate the data in the first left and right cells then create and populate in a new row. Hopefully someone could point me in the right direction.Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted March 19, 2006 Share Posted March 19, 2006 Here's a sample script. Define NUMCOLS as required.[code]define ("NUMCOLS", 2);$res = mysql_query("SELECT columname1, columname2 FROM tablename");$count = 0;echo "<TABLE border=1>";while (list($col1, $col2) = mysql_fetch_row($res)) { if ($count % NUMCOLS == 0) echo "<TR>\n"; # new row echo "<TD>$col<br>$col2</TD>\n"; $count++; if ($count % NUMCOLS == 0) echo "</TR>\n"; # end row}if ($count % NUMCOLS != 0) { # end row if not already ended while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</TR>\n";}echo "</TABLE>";[/code] 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.