proctk Posted July 18, 2007 Share Posted July 18, 2007 Hi the below code will return information from a mysql table. The page that the results will be displayed on is divided in two colums. how do I get the results to print in alternate rows. So the record one goes to column one record two goes to column two record three goes to column 1 and so on thank you for any help <?php // Get buddies $query_get_buddy = ("SELECT * from Buddylink WHERE owner_id = '$user_id' AND status = '2'"); $get_buddy = mysql_query($query_get_buddy)or die("SQL Error: $query_get_buddy<br>" . mysql_error()); while ($buddy = mysql_fetch_assoc($get_buddy)){ $buddy_id = $buddy['buddy_id']; $query_buddy_albums = ("SELECT * FROM albumNames WHERE user_id = '$buddy_id'"); $buddy_album = mysql_query($query_buddy_albums)or die("SQL Error: $query_buddy_albums<br>" . mysql_error()); while($album = mysql_fetch_assoc($buddy_album)){ ?> <div class="boxContainerLeft"> </div> <div class="boxContainerRight"> </div> <?php } }?> Link to comment https://forums.phpfreaks.com/topic/60669-solved-print-alternate-rows/ Share on other sites More sharing options...
trq Posted July 18, 2007 Share Posted July 18, 2007 <?php $i = 0; while($album = mysql_fetch_assoc($buddy_album)){ $col = ($i % 2) ? 'boxContainerLeft' : 'boxContainerRight'; echo "<div class=\"$col\">"; echo $album['album_name']; echo "</div>"; $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/60669-solved-print-alternate-rows/#findComment-301830 Share on other sites More sharing options...
proctk Posted July 19, 2007 Author Share Posted July 19, 2007 Thank you that worked excellent Link to comment https://forums.phpfreaks.com/topic/60669-solved-print-alternate-rows/#findComment-301853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.