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
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.