results into two 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
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

results into two rows

Post by ianhull »

Hi Guys,

I have this

Code: Select all

$query = "SELECT id, module, companyname FROM modules WHERE companyname='$companyname'";
I need to get these results into two rows/columns on the page.

How would this be done?

Code: Select all

$result = mysql_query($query);

while ($line = mysql_fetch_array($result))    
{
extract($line);

echo ' <table width="100%" cellspacing="2" cellpadding="2"><tr><td>'.$module.'</td><td>'.$module.'</td></tr></table> ';
}
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

$result = mysql_query($query) or die($query);

echo '<table><tr><th>table</th>';
$i = 0;
while ($row = mysql_fetch_array($result))   
{
	if ( 0==$i++%2 ) {
		echo '</tr><tr>';
	}
	echo '<td>', htmlentities($row['module']),'</td><td>', htmlentities($row['module']), '</td>';
}
echo '</tr></table>';
see http://www.php.net/manual/en/language.o ... hmetic.php
Post Reply