PHP mysqli_num_rows() mysql select empty counting

Posted under » PHP » MySQL on 20 May 2017

Sometimes you need to know if your SQL query is empty. For example, is there someone living in Alaska in your table. If there nobody then you won't show the map of Alaska.

$result = mysql_query("select city from USA WHERE city = '$rid'" );
$rowcount = mysql_num_rows($result);
if ($rowcount > 0) { exit("Sorry. there is nothing to show.");  }
or if using mysqli
$result = mysqli_query("select city from USA WHERE city = '$rid'" );
$rowcount = mysqli_num_rows($result);
if ($rowcount > 0) { exit("Sorry. there is nothing to show.");  }

Read about this practical use of pagination.

web security linux ubuntu GIT svn Raspberry apache mysql php drupal cake symfony javascript Ajax css