web_master Posted May 6, 2007 Share Posted May 6, 2007 Hi, how can I list from database in 2 or 3 column... <table width="100" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <?php $query_return=mysql_query("SELECT * FROM table ORDER BY table_id ASC"); while ($request=mysql_fetch_array($query_return)) { ?> <!-- this table need to listed in 2 or more column --> <table width="100" border="0" cellspacing="0" cellpadding="0"> <tr> <td><?print $request['id'];?></td> <td><?print $request['work'];?></td> </tr> <tr> <td><?print $request['home'];?></td> <td><?print $request['work'];?></td> </tr> </table> <? }?> </td> </tr> </table> thanx Link to comment https://forums.phpfreaks.com/topic/50221-list-in-2-or-more-column/ Share on other sites More sharing options...
Barand Posted May 6, 2007 Share Posted May 6, 2007 not sure what you are trying to achieve. ??? Link to comment https://forums.phpfreaks.com/topic/50221-list-in-2-or-more-column/#findComment-246566 Share on other sites More sharing options...
web_master Posted May 6, 2007 Author Share Posted May 6, 2007 I want to list the table in a 2 or 3 cols... Maybe its better like this: <table width="100" border="0" cellspacing="0" cellpadding="0"> <?php $query_return=mysql_query("SELECT * FROM table ORDER BY table_id ASC"); while ($request=mysql_fetch_array($query_return)) { ?> <tr> <td><table... $id1 .../table></td> <td><table... $id2 .../table></td> <td><table... $id3 .../table></td> </tr> <tr> <td><table... $id4 .../table></td> <td><table... $id5 .../table></td> <td><table... $id6 .../table></td> </tr> <?php } ?> </table> Link to comment https://forums.phpfreaks.com/topic/50221-list-in-2-or-more-column/#findComment-246571 Share on other sites More sharing options...
Barand Posted May 6, 2007 Share Posted May 6, 2007 Example code <?php // author: Barand include 'db.php'; // connection stuff define ("NUMCOLS",3); $res = mysql_query("SELECT col1, col2 FROM mytable"); $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>$col1<br>$col2</TD>\n"; $count++; if ($count % NUMCOLS == 0) echo "</TR>\n"; # end row } # end row if not already ended if ($count % NUMCOLS != 0) { while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</TR>\n"; } echo "</TABLE>"; ?> Link to comment https://forums.phpfreaks.com/topic/50221-list-in-2-or-more-column/#findComment-246575 Share on other sites More sharing options...
web_master Posted May 6, 2007 Author Share Posted May 6, 2007 Barand, Youre great! thank You! Link to comment https://forums.phpfreaks.com/topic/50221-list-in-2-or-more-column/#findComment-246582 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.