How to list records for a query and to display \"no records\" when no rows returned using a single query?
Currently I am using a COUNT(*)
query or using
Try Something like following
if (mysql_num_rows == '0')
'No Records'
else
//YOUE CODE HERE
Important: I assume that the OP uses PHP as (s)he mentions mysql_num_rows
. And I hope (s)he will tell me if I am wrong.
It is your job in PHP to check whether the result is an empty set or not. I don't understand why you have to do another query. Maybe you have to clarify your question.
Here a more complete example:
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table1", $link);
// If if result set contains rows
if(0 == mysql_num_rows($result)) {
echo 'no records';
}
else { // Loop over the result set
while(row = mysql_fetch_array($result)) {
// do whatever you want with the data here
}
}
Reference: mysql_num_rows, mysql_fetch_array
Even if you don't use PHP, the approach is the same in other languages and there should be similar functions available.
why do you need another query after mysql_num_rows?
why not to just run your query and then check results with mysql_num_rows?