Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to split MySQL table records in half to display on each side of a page
- $numRows=mysql_num_rows(mysql_query("SELECT * FROM cultures"));
- $half = $numRows/2;
- $result = mysql_query("SELECT * FROM cultures ORDER BY name ASC LIMIT ".$half);
- while($row = mysql_fetch_array($result)) {
- $url = "artists.php?culture=".ucfirst($row['name']);
- echo '<div class="homepage_culture_item">
- <a href="'.$url.'"></a>
- <img src="/images/flags/'.$row['name'].'.png" style="width: 30px; vertical-align: middle; margin-right: 10px;" />'.$row['name'].'
- </div>
- <br />';
- }
- $half = floor($numRows/2);
- $result = mysql_query("SELECT * FROM cultures ORDER BY name ASC");
- $half = floor(mysql_num_rows($result)/2);
- $count = 0;
- // First side.
- while($count <= $half
- && $row = mysql_fetch_array($result))
- {
- // ...
- $count++;
- }
- // ...
- // Second side.
- while($row = mysql_fetch_array($result))
- {
- // ...
- }
- $result = mysql_query("SELECT * FROM cultures ORDER BY name ASC");
- $i = 0;
- while($row = mysql_fetch_array($result)){
- $i++
- if($i % 2){
- //echo right aligned div
- }
- else{
- //echo left aligned div
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment