Forum Moderators: coopster
$mystory = 'mystory'; // Whatever story you want to search
$query = "SELECT COUNT(comments) FROM mytable WHERE story = '$mystory'";
$result = mysql_query($query) or die("Could not get comments for $mystory");
$row = mysql_fetch_row($result);
$num = $row[0];
// Echo the count
echo "The count is $num";
Table names and such are examples of course.
[edited by: Duskrider at 3:12 pm (utc) on June 29, 2007]
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
just add your WHERE CLAUSE
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
It is not a good practice to use mysql_num_rows() to determinate the number of results. In your case, all the table1 content will be loaded into the memory and after that, the result records will be counted.
What about the table1 content is very large? Or just exceed the mysql memory limit? The database server will "freeze".