Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 columns with 1 query

Status
Not open for further replies.

tektipsismyfavorite

Technical User
May 4, 2006
57
US
I'm trying a "do" loop to list out a list from a query. I want the list to wrap into the next cell when it gets halfway finished. This is the code I'm using, but for some reason, it's not calculating correctly and it's duplicated the record that is at the halfway point.
Code:
<table cellpadding="1" cellspacing="0" border="0" width="260">
	<tr>
		<td width="130" align="left" valign="top">
		<?php $half = $totalRows_cl*.5; $halfway = round($half); $i=1; ?>
		<?php do { 
		if($i < $halfway){ ?>
		    	<a href="details.php?c=<?php echo $row_cl['clientid']; ?>"><?php echo $row_cl['cname']; ?></a><br />
		<?php $i++; } if($i == $halfway){ ?>
			<a href="details.php?c=<?php echo $row_cl['clientid']; ?>"><?php echo $row_cl['cname']; ?></a>
			</td><td width="130" align="left" valign="top">
		<?php $i++; } if($i > $halfway){ ?>
			<a href="details.php?c=<?php echo $row_cl['clientid']; ?>"><?php echo $row_cl['cname']; ?></a><br />
		<?php $i++; } } while ($row_cl = mysql_fetch_assoc($cl)); ?>
		</td>
	</tr>
</table>
 
Ok, i realized, i just need to re-order my statements to:
Code:
<table cellpadding="1" cellspacing="0" border="0" width="260">
	<tr>
		<td width="130" align="left" valign="top">
		<?php $half = ($totalRows_cl)*.5; $halfway = round($half); $i=1; ?>
		<?php do { if($i > $halfway){ ?>
			 <a href="details.php?c=<?php echo $row_cl['clientid']; ?>"><?php echo $row_cl['cname']; ?></a><?php echo $i; ?><br />
		<?php $i++; } if($i == $halfway){ ?>
			<a href="details.php?c=<?php echo $row_cl['clientid']; ?>"><?php echo $row_cl['cname']; ?></a><?php echo $i; ?>
			</td><td width="130" align="left" valign="top">
		<?php $i++; } if($i < $halfway){ ?>
			<a href="details.php?c=<?php echo $row_cl['clientid']; ?>"><?php echo $row_cl['cname']; ?></a><?php echo $i; ?><br />
		<?php $i++; } } while ($row_cl = mysql_fetch_assoc($cl)); ?>
		</td>
	</tr>
</table>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top