affc Posted May 16, 2009 Share Posted May 16, 2009 Hey, I am trying to now change the code so if diplays from this: 1 4 2 5 3 6 to this 1 2 3 4 5 6 Here is my code but I have no idea how to change it, hopefully its easy enough, thanx <?php $columns = 2; $sql="SELECT * FROM newsdetails ORDER BY year DESC, fileno DESC"; $result = mysql_query($sql) or die("Couldn't execute query."); $num_rows = mysql_num_rows($result); $rows = ceil($num_rows / $columns); while($row = mysql_fetch_array($result)) { $data[] = $row['TEXT']; $data1[] = $row['Date']; $data2[] = $row['file']; $data3[] = $row['Title']; } ?> <table width="600" border="0"> <? for($i = 0; $i < $rows; $i++) { ?> <tr> <? for($j = 0; $j < $columns; $j++) { if(isset($data[$i + ($j * $rows)])) { ?> <td width="150"><img src="images/<? echo $data1[$i + ($j * $rows)]; ?>_<? echo $data2[$i + ($j * $rows)]; ?>_001_L.gif" width="170"></td> <td width="150" valign="top"><a href="index.php?year=<? echo $data1[$i + ($j * $rows)]; ?>&no=<? echo $data2[$i + ($j * $rows)]; ?>"><font color="#FFFFFF" size="2" face="Times New Roman, Times, serif"><strong><? echo $data3[$i + ($j * $rows)]; ?></strong></font></a><br><br> <font color="#00FFFF" size="2" face="Times New Roman, Times, serif"><em><? echo $data[$i + ($j * $rows)]; ?></em></font></td> <? } } ?></tr> <? } ?></table> Quote Link to comment https://forums.phpfreaks.com/topic/158361-solved-display-results-in-2-columns-from-left-to-right-not-top-to-bottom/ Share on other sites More sharing options...
affc Posted May 16, 2009 Author Share Posted May 16, 2009 Maybe its not possible? Thought you could just about do anything with php i guess not, lol im still new so still alot to learn Quote Link to comment https://forums.phpfreaks.com/topic/158361-solved-display-results-in-2-columns-from-left-to-right-not-top-to-bottom/#findComment-835207 Share on other sites More sharing options...
Mark Baker Posted May 16, 2009 Share Posted May 16, 2009 You don't show how you're displaying the data in two columns at the moment, simply building an array. <?php $columns = 2; $sql="SELECT * FROM newsdetails ORDER BY year DESC, fileno DESC"; $result = mysql_query($sql) or die("Couldn't execute query."); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { $row = 0; while($row = mysql_fetch_array($result)) { if ($row % $columns == 0) { if ($row > 0) echo '</tr>'; echo '<tr>'; } echo '<td>'; echo $row['TEXT']; echo $row['Date']; echo $row['file']; echo $row['Title']; echo '</td>'; $row++; } if ($row % $columns != 0) echo '<td></td>'; echo '</tr>'; } else { echo 'No data returned'; } Quote Link to comment https://forums.phpfreaks.com/topic/158361-solved-display-results-in-2-columns-from-left-to-right-not-top-to-bottom/#findComment-835220 Share on other sites More sharing options...
affc Posted May 16, 2009 Author Share Posted May 16, 2009 I dont understand what you mean? The code I have their displays everything I need in columns etc just displays it like this: 1 4 2 5 3 6 As some of the code is HTML and the other part PHP, I cannot get this forum to highlight the whole lot but all the code is above you should see the Table tags etc, Quote Link to comment https://forums.phpfreaks.com/topic/158361-solved-display-results-in-2-columns-from-left-to-right-not-top-to-bottom/#findComment-835233 Share on other sites More sharing options...
affc Posted May 16, 2009 Author Share Posted May 16, 2009 I see what you mean, you have to scroll down in my first posted CODE and the rest is there. It produces 2 columns but I am trying to get the columns to display like this: 1 2 3 4 5 6 Quote Link to comment https://forums.phpfreaks.com/topic/158361-solved-display-results-in-2-columns-from-left-to-right-not-top-to-bottom/#findComment-835245 Share on other sites More sharing options...
Ken2k7 Posted May 16, 2009 Share Posted May 16, 2009 <?php $columns = 2; $sql="SELECT * FROM newsdetails ORDER BY year DESC, fileno DESC"; $result = mysql_query($sql) or die("Couldn't execute query."); echo '<table><tr>'; $count = 0; while ($row = mysql_fetch_assoc($result)) { if (!empty($count) && $count % $columns == 0) echo '</tr><tr>'; echo '<td>' , $row['TEXT'] , '<br />' , $row['Date'] , '<br />' , $row['file'] , '<br />' , $row['Title'] , '</td>'; $count++; } I think that should do it. Quote Link to comment https://forums.phpfreaks.com/topic/158361-solved-display-results-in-2-columns-from-left-to-right-not-top-to-bottom/#findComment-835263 Share on other sites More sharing options...
affc Posted May 17, 2009 Author Share Posted May 17, 2009 Wow that script looks simple and yet its so effective Thanks Quote Link to comment https://forums.phpfreaks.com/topic/158361-solved-display-results-in-2-columns-from-left-to-right-not-top-to-bottom/#findComment-835788 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.