Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 1.13 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.     }