Jump to content

Problem with mysql_num_rows


cgm225

Recommended Posts

If I connect to my database and use the mysql_num_rows() function as follows I have NO problems::

 

    $gallery_db_connection = mysql_connect($gallery_DB_host,$gallery_DB_user,$gallery_DB_password);
    mysql_select_db($gallery_DB_name, $gallery_db_connection);

    if ((mysql_num_rows(mysql_query("SELECT * FROM images WHERE album = $album_id ORDER BY timestamp DESC LIMIT $upper_limit, 1",$gallery_db_connection))) > 0) { 
            echo "Entries present!";}

 

However, if I try to use the following function before the code outlined above, a function that connects to another database to get user/privilege information, the above mysql_num_rows() function returns with the following error:: "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /web/example.com/includes/php/gallery/photos.inc.php on line 164."

 

This is what does NOT work::

 

    //Database connection exactly as previously stated in the above CODE block
    $gallery_db_connection = mysql_connect($gallery_DB_host,$gallery_DB_user,$gallery_DB_password);
    mysql_select_db($gallery_DB_name, $gallery_db_connection);

    //Checks for permissions to perform various gallery actions based on username
    function permission_for($permission) {
        $username = $_SESSION['username'];

        $authentication_db_connect = mysql_connect("mysql.internal","example_user","example_password");
        mysql_select_db("example_authentication",$authentication_db_connect);

        if (mysql_num_rows(mysql_query("SELECT * FROM permissions WHERE username = '$username' AND permission = '$permission'",$authentication_db_connect)) > 0) {
                return TRUE;
            } else {
                return FALSE;
            }

        mysql_close($authentication_db_connect);
    
    }

    if (permission_for("complete_thumbnail_generation") == TRUE) {echo "Permission granted!";}

    //If statement exactly as previously stated in the above CODE block, but now outputting error.
    if ((mysql_num_rows(mysql_query("SELECT * FROM images WHERE album = $album_id ORDER BY timestamp DESC LIMIT $upper_limit, 1",$gallery_db_connection))) > 0) { 
            echo "Entries present!";}

 

Any ideas why I am getting this error?

 

Thank you all in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/92772-problem-with-mysql_num_rows/
Share on other sites

$authentication_db_connect = mysql_connect("mysql.internal","example_user","example_password");
mysql_select_db("example_authentication",$authentication_db_connect);
$query ="SELECT * FROM permissions WHERE username = '$username' AND permission = '$permission'"; 
$query =mysql_query($query) or die(mysql_error());

if (mysql_num_rows($query ,$authentication_db_connect) > 0) {
return TRUE;
} 
else {
return FALSE;
}

 

try and tell us what happen

Using the code you provided in the location of where the function is in the above code block, I get the following error message: "Warning: Wrong parameter count for mysql_num_rows() in /web/example.com/includes/php/gallery/photos.inc.php on line 148"

 

 

Also, this post is a restatement/excerpt of a previous post from a day or two ago.  See http://www.phpfreaks.com/forums/index.php/topic,183742.msg822642.html#msg822642

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.