Netdancer Posted March 10, 2009 Share Posted March 10, 2009 I sure this is reall easy but I new to PHP - in ASP I would simply put a rs.movenext between the <TD >TAGS need to display Row1 | row3 row4 | row5 till eof what I have now is <?php do { ?> <tr> <td width="50%"><a href="http://<?php Echo $row_RS2['URL'] ?>" target="_blank" class="V12"> <?php Echo $row_RS2['employer'] ?> </a></td> <td><a href="http://<?php Echo $row_RS2['URL'] ?>" target="_blank" class="V12"> <?php Echo $row_RS2['employer'] ?> </a></td> </tr> <?php } while ($row_RS2 = mysql_fetch_assoc($RS2)); ?> with just displays same data twice on each row - need to move to next row any help will be appreciated Ted Quote Link to comment https://forums.phpfreaks.com/topic/148841-loop-thru-data-and-display-in-2-colums/ Share on other sites More sharing options...
aebstract Posted March 10, 2009 Share Posted March 10, 2009 Run your results through a loop, set a variable to 1 before the loop, then if the number is odd you can just put it in the left column, if it is even put it in the right. Or however you need to structure it. Quote Link to comment https://forums.phpfreaks.com/topic/148841-loop-thru-data-and-display-in-2-colums/#findComment-781584 Share on other sites More sharing options...
grissom Posted March 10, 2009 Share Posted March 10, 2009 A neat way to see if a number is odd or even is to do a logical AND with 1 and see if the result is zero or one. Quote Link to comment https://forums.phpfreaks.com/topic/148841-loop-thru-data-and-display-in-2-colums/#findComment-781588 Share on other sites More sharing options...
Philip Posted March 10, 2009 Share Posted March 10, 2009 Or the modulus operator. Not tested, just thrown together quickly: <?php $i = 0; do { if($i%2==0) { ?> <tr> <td width="50%"><a href="http://<?php Echo $row_RS2['URL'] ?>" target="_blank" class="V12"> <?php Echo $row_RS2['employer'] ?> </a></td> <?php } else { ?> <td><a href="http://<?php Echo $row_RS2['URL'] ?>" target="_blank" class="V12"> <?php Echo $row_RS2['employer'] ?> </a></td> </tr> <?php } $i++; } while ($row_RS2 = mysql_fetch_assoc($RS2)); if($i%2>0) { echo '<td></td></tr>'; // in case of ending in an odd number of columns } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148841-loop-thru-data-and-display-in-2-colums/#findComment-781593 Share on other sites More sharing options...
Netdancer Posted March 10, 2009 Author Share Posted March 10, 2009 Thank you , thank you, thank you I just had to add the table tags and it works great <?php $target= $_REQUEST['target']; mysql_select_db($DBName, $militaryEdge); //echo $DBName; $query_RS2 = "SELECT * FROM jobfair_employers order by sort_order"; $RS2 = mysql_query($query_RS2, $militaryEdge) or die(mysql_error()); $row_RS2 = mysql_fetch_assoc($RS2); $totalRows_RS2 = mysql_num_rows($RS2); ?> <table> <?php $i = 0; do { if($i%2==0) { ?> <tr> <td width="50%"><a href="http://<?php Echo $row_RS2['URL'] ?>" target="_blank" class="V12"> <?php Echo $row_RS2['employer'] ?> </a></td> <?php } else { ?> <td><a href="http://<?php Echo $row_RS2['URL'] ?>" target="_blank" class="V12"> <?php Echo $row_RS2['employer'] ?> </a></td> </tr> <?php } $i++; } while ($row_RS2 = mysql_fetch_assoc($RS2)); if($i%2>0) { echo '<td></td></tr>'; // in case of ending in an odd number of columns } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/148841-loop-thru-data-and-display-in-2-colums/#findComment-781599 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.