Hiya All,

Not sure if i should be putting thi up on the SQL section but i think the problem lies in the PHP part of my code.

This is what i've got. I'm counting the number of times a category shows up in my database returning the name of that category with the count next to it.
I'm printing the first 5 results individually then putting the rest into a dropdown box (order by count)

My problem is there is a category missing (schools__30) which would be the 6th result in line i.e. the first to appear in the dropdow box.
The code is below any help much appreciated,


$sql = "SELECT Company.Classification, COUNT(DISTINCT Company.Name) as 'Number'
FROM Company WHERE Company.Classification<>'' GROUP BY Company.Classification ORDER BY Number DESC";
$result = mysql_query($sql);

  echo "<a href='http://www." . $nt['Classification'] . ".html' target='_blank'>" . $nt[Classification] . "____" . $nt
  [Number] . "</a><br /> ";
echo "<select onchange='window.location.href=this.options[this.selectedIndex].value'>";

echo "<option value='http://www." . $nt[Classification] . ".html'>" . $nt[Classification] . "____" . $nt[Number] . "</option> ";

echo "</select>";

Recommended Answers

All 4 Replies

I'm about 90% sure it's because your first while loop gets the 6th row before you break out of the loop and doesn't display it. The only way I can think of fixing it is to to break at the end of it:

if($i == 5){

try below code on line 16 (above 2nd while loop)

mysql_data_seek($result, 0);

encypted i thought i'd be something to do with exiting the loop. Will give both suggestions a go and let you know,


while you're there, do you know if there is a way i can ORDER results 6 and upwards by Name as apposed to Number byt still keep the seperate top 5 as they are.
If not i'll just harcode it no biggy.


duh stupid me just realised i put (while <=5) where as i should be just '< 5' because the count is reaching 5 and still adding 1.

thanks guys you opened my tired eyes there.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.