Page 1 of 1

how to display data in 2 columns

Posted: Sun Sep 28, 2008 12:50 am
by mozer
i need help!!!
i need to display the following table in 2 columns instead of 1.

function displaySupConCompany()
{
$result = mysql_query("SELECT SupConCompany FROM `suppliercontacts` ORDER BY `suppliercontacts`.`SupConCompany` ASC");
print("<table border='1'>");
while ($i<=20 and $row = mysql_fetch_row($result))
{
print("<tr>");
foreach ($row as $col)
{
$i++;
print("<td><a href=\"suppliercontacts_ismail_muad.php?id=$id\">$col</a></td>");
}
print("</tr>");
}

thanks

Re: how to display data in 2 columns

Posted: Sun Sep 28, 2008 2:17 pm
by califdon
Think about it this way: The reason it now prints in one column is that you are printing a <tr> tag before every record and a </tr> tag after every record. So instead, only do that before/after every second record. In other words, in both cases, use an if test and only print them if $i is evenly divisible by 2. You will also have to test at the end of your while loop and if the last value of $i was odd, add a final </tr> tag.

An easy way to test whether a value is evenly divisible by 2 is:

Code: Select all

if( ($i % 2) == 0 )

Re: how to display data in 2 columns

Posted: Mon Sep 29, 2008 1:18 am
by mozer
Thank you kindly!
:lol: