Splitting Query to 2 columns

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
curseofthe8ball
Forum Commoner
Posts: 73
Joined: Sun Jun 01, 2003 12:33 am

Splitting Query to 2 columns

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Read the second thread linked from Useful Posts.
Post Reply