PHP not displaying ALL records from database -RESOLVED

Greetings fellow PHP-ers.
I’m a part-time PHP user, and use it mostly for content management databases and to make common headers/footers/etc for my websites.
Anywho… here’s my dilemna

I have created a database of Karaoke songs.
I am uploading chunks of data using csv files modified by myself.
No problems there.
I now have a database with 1210 rows of data.
When I output to the web page, I only get 1180 rows.
There must be some reason that it’s a round number, but my research for an answer turned up scratch.
I am using a Linux/Apache 1.3.33 Server, PHP Version 4.3.11, and MySQL 5.0.18
These are in seperate files and I use includes to put it together, but here’s the code together:

$hostname="mysqlserver"; //not actual
$username="mmkaraoke";
$password="password"; //not actual
$dbname="mmkaraoke";
$usertable="list";
$display[1] = "id";
$display[2] = "track";
$display[3] = "song";
$display[4] = "artist";
$display[5] = "code";
$display[6] = "mandm";

mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname);

// HTML header inserted here

<br><br>
<table border=1 class='karaoke'>
<tr>
<td>#</td>
<td>Track<br>#</td>
<td><a href="index.php?orderBy=2&sort=<?=$sort?>">Song Title</a></td>
<td><a href="index.php?orderBy=3&sort=<?=$sort?>">Artist</a></td>
<td><a href="index.php?orderBy=4&sort=<?=$sort?>">CD Code</a></td>
</tr>
<?php

$sort = "ASC";
if(isset($_GET["sort"]) && !empty($_GET["sort"])) {
  $sort = ($_GET["sort"]=="ASC") ? "DESC" : "ASC";
}

$order_query = " ORDER BY song,artist,code $sort";

if( isset($_GET["orderBy"]) && !empty($_GET["orderBy"]) ) {
 switch ($_GET["orderBy"]) {
  case 2:
      $order_query = " ORDER BY song $sort";
      break;
  case 3:
      $order_query = " ORDER BY artist $sort";
      break;
  case 4:
      $order_query = " ORDER BY code $sort";
      break;

  default:
      $order_query = " ORDER BY song,artist,code $sort";
      break;
 }
}

$query = "SELECT * FROM $usertable Group By song,artist,code" . $order_query;
$result = mysql_query($query);
if ($result) {
    while($row = mysql_fetch_array($result)) {
        $i+=1;
        $d ="<tr>";
        $d.="<td width=30>".$i."</td>";
        $d.="<td width=30>".$row["$display[2]"]."</td>";
        $d.="<td width=300 align='left'>".$row["$display[3]"]."</td>";
        $d.="<td width=300 align='left'>".$row["$display[4]"]."</td>";
        $d.="<td width=50>".$row["$display[5]"]."</td>";
        $d.="</tr>";
        echo $d;
    }
}
?>
</table>

//HTML footer here

Everything works great, except it only displays 1180 rows from the database.
I log in to phpMyAdmin, and there’s 1210 rows in the database.
You can see the result at http://karaoke.maryandmarthashouse.com

Am I missing something obvious? Is there a sorting limitation? I couldn’t find any info about it. Please help.

Thanks in advance for any replies.

Even though it wasn’t directly related, I saw in another post that someone mentioned Group By adding a Limit, so I did some more internet research and tried just removing the Group By in my code, and all the records display fine now.

I had copied someone elses sorting code, and didn’t know why they had added it, but it works perfectly for me without it.

Thanks for your good thoughts, though, and more to the PHP coder who made that statement to get me thinking, I hate it when that happens.

Hopefully this post will help someone else who needs it.

Mark,
I just wanted to say thank you for posting your resolution, it could very well help someone out later down the road.

Sponsor our Newsletter | Privacy Policy | Terms of Service