Jump to content

List in 2 or more column


web_master

Recommended Posts

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

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>

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>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.