Guest User

Untitled

a guest
May 4th, 2012
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. How to split MySQL table records in half to display on each side of a page
  2. $numRows=mysql_num_rows(mysql_query("SELECT * FROM cultures"));
  3. $half = $numRows/2;
  4.  
  5. $result = mysql_query("SELECT * FROM cultures ORDER BY name ASC LIMIT ".$half);
  6. while($row = mysql_fetch_array($result)) {
  7. $url = "artists.php?culture=".ucfirst($row['name']);
  8. echo '<div class="homepage_culture_item">
  9. <a href="'.$url.'"></a>
  10. <img src="/images/flags/'.$row['name'].'.png" style="width: 30px; vertical-align: middle; margin-right: 10px;" />'.$row['name'].'
  11. </div>
  12. <br />';
  13. }
  14.  
  15. $half = floor($numRows/2);
  16.  
  17. $result = mysql_query("SELECT * FROM cultures ORDER BY name ASC");
  18. $half = floor(mysql_num_rows($result)/2);
  19. $count = 0;
  20.  
  21. // First side.
  22. while($count <= $half
  23. && $row = mysql_fetch_array($result))
  24. {
  25. // ...
  26. $count++;
  27. }
  28.  
  29. // ...
  30.  
  31. // Second side.
  32. while($row = mysql_fetch_array($result))
  33. {
  34. // ...
  35. }
  36.  
  37. $result = mysql_query("SELECT * FROM cultures ORDER BY name ASC");
  38.  
  39. $i = 0;
  40. while($row = mysql_fetch_array($result)){
  41. $i++
  42. if($i % 2){
  43. //echo right aligned div
  44. }
  45. else{
  46. //echo left aligned div
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment