Page 1 of 1

Splitting Query to 2 columns

Posted: Wed Aug 30, 2006 3:00 pm
by curseofthe8ball
I've got the below code that works perfectly in terms of splitting the results of a query to 2 columns, however it lays the results out in the following format:

A B
C D
E F
G H

I'm trying to get it to lay it out this way:

A E
B F
C G
D H

The code looks like this. Any help to edit to format the way I've explained above is much appreciated!

Code: Select all

<table width='569' border='0' cellpadding='0' cellspacing='0' class='ten'>
<tr>
   <td colspan='6'>&nbsp;</td>
</tr>
<tr valign='top'>";

$cols = 2;
$di =1;
	
$query = mysql_query("SELECT id, title FROM practice_areas WHERE status = 'active' ORDER BY 'title' ASC");
while ($myrow = mysql_fetch_array($query)) {

if (is_int($di / $cols)) {

print '<td width="9">&#8226;</td>
<td width="281"><a href=practice-areas.php?action=view&id='.$myrow["id"].'>'.$myrow["title"].'</a></td>
</tr>
<tr valign="top">
<td height="10" colspan="6"><img src="images/spacer.gif" width="1" height="1"></td>
</tr>
<tr valign="top">'; 

}

else {

print '<td width="8">&nbsp;</td>
<td width="9">&#8226;</td>
<td width="252"><a href=practice-areas.php?action=view&id='.$myrow["id"].'>'.$myrow["title"].'</a></td>
<td width="10">&nbsp;</td>'; 

}

$di++;

}
		
print '<tr>
<td colspan="6">&nbsp;</td>
</tr>
</table>

Posted: Wed Aug 30, 2006 3:56 pm
by feyd
Read the second thread linked from Useful Posts.