You are here: RE: [PHP] Walking through a bunch of MySQL Records « PHP « IT news, forums, messages
RE: [PHP] Walking through a bunch of MySQL Records

Posted by Jim Moseby on 11/14/05 21:28

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация