RE: [PHP] Walking through a bunch of MySQL Records
| From: | Jim Moseby | Date: | Mon, 14 Nov 2005 19:28:34 +0000 |
| Subject: | RE: [PHP] Walking through a bunch of MySQL Records | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-225763@lists.php.net to get a copy of this message | ||
>
> I have a question.
> I want to display a group of records pulled form a MySQL db
> in the following
> fashion.
>
> 1 6
> 2 7
> 3 8
> 4 9
> 5 10
>
> Now I can easily figure out how to display the records as
>
> 1 2
> 3 4
> 5 6
> 7 8
> 9 10
>
> But since I am in an HTML table and the need to display the
> <TR> and </TR> I
> am not sure how to make th logic so that I can get the first
> listing. Can
> anyone help me out?? Need more information??
You could load up an array with your result set:
$records=array();
$rownum=0;
while ($row=mysql_fetch_array($result)){
$rownum++;
records[$rownum]=$row['data'];
}
...then use $rownum/2 to determine the second column:
for ($i==1;$i<=$rownum/2;$i++){
$col1=$i;
$col2=$i+($rownum/2);
echo "<tr>$record[$col1]</tr>";
echo "<tr>$record[$col2]</tr>";
}
There are probably much better ways to do this, but this is a start.
JM