Jump to content

Recommended Posts

Hey forum.
I have this loop wich with all my other code displayes all the tables in a database and create's a select box for them. This is all good and working. But how can i make it that when it loops over a certain amount of times it will display all the select boxes after the ammount beside the original ones?

[code]echo "<table border='1'>";
        // For each row, print the name!
for ($j=0; $j < $field_count; $j++) {
            echo "<tr>";
            $field = pg_fieldname($sql_query,$j);
            echo "<td><input type='checkbox' name=$field value=$field checked='checked'></td>";
          echo "<td>View--$field </td>";
          echo "</tr>";
    }
    echo "</table>";
    echo "<hr>";[/code]
That puts out a list like this

[code]
ITEM...
ITEM...
ITEM...
ITEM...
ITEM...
ITEM...
ITEM...
ITEM...
[/code]
But i want it to look like this:

[code]
ITEM...     ITEM...
ITEM...     ITEM...
ITEM...     ITEM...
ITEM...     ITEM...
[/code]

With a while loop, but how? And if it has over a second ammount, display them next to that!


[code]
ITEM...     ITEM...     ITEM...
ITEM...     ITEM...     ITEM...
ITEM...     ITEM...     ITEM...
ITEM...     ITEM...     ITEM...
[/code]
Cheers,
Nathan
Link to comment
https://forums.phpfreaks.com/topic/11389-tables-and-layout/
Share on other sites

[code]
<?php
$field_count = 50; //example # of results
$colnum = 10; //example heigth of column

echo "<table border='1'><tr><td valign = 'top'>";
echo "<table border='1'>";
$x = 1;
for ($j = 0; $j < $field_count; $j++) {
     echo "<tr>";
   echo "<td><input type='checkbox' name='field' value='blah' checked='checked'></td>";
          echo "<td>View--$j </td>";
          echo "</tr>";
   if ($x == '10') {
       echo "</table></td><td valign='top'><table border='1'>";
         $x = 0;
     }
     $x++;
}
echo "</td></tr></table>";
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/11389-tables-and-layout/#findComment-42714
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.