Page 1 of 1

results into two rows

Posted: Sun Sep 17, 2006 5:17 pm
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.

Posted: Sun Sep 17, 2006 5:26 pm
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