Search code examples
mysql-num-rows

mysql_num_rows causes an error message


My simplified code is:

<?php
$con = mysql_connect("aaa", "bbb", "ccc", "ddd");
$sql = "SELECT * FROM list";
$result = mysql_query($sql,$con);
echo mysql_num_rows($result);
?>

I get the following error: "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test\mysqli_num_rows.php on line 4"

Can anyone tell me whats wrong with that (simplified) code? Thanks


Solution

  • Does this work?

    <?php
    $con = mysql_connect("aaa", "bbb", "ccc", "ddd");
    mysql_select_db("database", $con);
    $sql = "SELECT * FROM list";
    $result = mysql_query($sql,$con);
    echo mysql_num_rows($result);
    ?>