mysql_num_rows is pretty simple.
If you run a SELECT query
$result = mysql_query("SELECT blahblahblah");
then mysql_num_rows($result);
will say how many rows were returned in the result. So if there were three results returned by the query, mysql_num_rows() will tell you so.
Here's how I usually loop over a database query:
$sql = "SELECT blahblahblah";
$result = mysql_query($sql);
$result_count = mysql_num_rows($result);
if($result_count==0)
{ // Gracefully handle the situation when
// no results are returned.
}
else
{ for($i=0; $i<$result_count; ++$i)
{ $row = mysql_fetch_array($result);
// And I can also use $i for indexing,
// alternating background colours, or whatever.
}
}
Faster than a while($result=mysql_fetch_array()) in particular, because I don't need to do an entire fetch_array just to find out I'm already at the end.
Now, your problem.
The thing is that you're asking for all the types listed, however many times they appear. You only want each distinct type in the table, not the type from every row in the table, which is what you're asking for now.
So try this query when getting the types:
SELECT DISTINCT type FROM tbl_sf_news ORDER BY type