[thelist] PHP/MySQL results in multiple table cells?

Michael Pemberton mpember at phreaker.net
Sat Sep 29 07:02:30 CDT 2001


I think you've got the wrong idea about the code.  $newData is a 2D array.

The main resons for doing it this way is that it fees up the MySQL connection
before it starts doing anything with the data.  This is very useful when you are
doing something that may take a while but doesn't need the connection after it
loads the initial dataset.

Here's the more accurate expansion:

<tr>
<?php
     $newData=array(); // this is where the data will be stored

     $connection = mysql_connect("localhost");
     $query="select thumb from images";
     $result=mysql_db_query("cdcollection",$query);
     $num_rows=mysql_num_rows($result);
     for ($i=1; $i<=$num_rows; $i++) $newData[]=mysql_fetch_array($result);
     mysql_close($connection);

     for ($i=1; $i<=$num_rows; $i++) {
        $currentRow = $newData[$i];
        echo "<td>".$currentRow[0]."</td>\n";
        if(($i % 3) == 0) {
            echo "</tr>\n<tr>\n";
        }
     }
?>
</tr>

Jeremy Ashcraft wrote:

> I'll expand a bit on Michael's code to fit your needs
>
> <tr>
> <?php
>      $newData=array(); // this is where the data will be stored
>
>      mysql_connect("localhost");
>      $query="select thumb from images";
>      $result=mysql_db_query("cdcollection",$query);
>      $num_rows=mysql_num_rows($result);
>
>      for ($i=1; $i<=$num_rows; $i++) {
>         $newData[]=mysql_fetch_array($result);
>         echo "<td>".$newData[0]."</td>\n";
>         if(($i % 3) == 0) {
>                 echo "</tr>\n<tr>\n";
>         }
>      }
> ?>
> </tr>
>
> or something to that effect.
> pretty much just looping through the results and every 3rd result, starting a
> new table row.
>
> jeremy
>
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt !

--
Michael Pemberton
mpember at phreaker.net
ICQ: 12107010








More information about the thelist mailing list