PHP and HTML table rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
knmwt15000
Forum Newbie
Posts: 8
Joined: Thu Apr 25, 2002 9:51 am

PHP and HTML table rows

Post by knmwt15000 »

I have some data in a mysql database and want it displaying in a table so that each row of data is displayed in a cell. I know how to do this bit but does anyone know how I can get it to start a new row every 4 cells so I doesnt just produce a long page or wide page.

thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

for ($i=0; $i!=mysql_num_fields($result);$i++)
{
   if ($i!=0 && $i%4==0) print('<br>');
   print('<span>'.$result&#1111;$i].'</span>');
&#125;
User avatar
knmwt15000
Forum Newbie
Posts: 8
Joined: Thu Apr 25, 2002 9:51 am

Post by knmwt15000 »

What? I don't get it.

come on guys. I use this code to output normally if this helps.

Code: Select all

<?php

$result = mysql_query("SELECT * FROM web_resources where category='journal' ",$db);

while ($myrow = mysql_fetch_array($result)) &#123;

		printf("
	<P class=normal><a href=%s>%s</a><br>
%s</p>
	
	\n",   $myrow&#1111;"webaddress"], $myrow&#1111;"name"], $myrow&#1111;"description"]);
&#125;
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

sorry, wasn't one of my better ones ;)

Code: Select all

<?php 
// ...<table><tr>
$result = mysql_query("SELECT * FROM web_resources where category='journal' ",$db);
$i=-1;
while ($myrow = mysql_fetch_array($result)) &#123; 
   if ($i==3) &#123; print('</tr><tr>'); $i=0; &#125; else $i++;
   printf("<td><span class="normal"><a href="%s">%s</a><br> 
%s</span></td>"
   , $myrow&#1111;"webaddress"], $myrow&#1111;"name"], $myrow"description"]); 
&#125; 
// ....</tr></table>
?>
Post Reply