cgm225 Posted February 24, 2008 Share Posted February 24, 2008 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! Quote Link to comment Share on other sites More sharing options...
teng84 Posted February 24, 2008 Share Posted February 24, 2008 $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 Quote Link to comment Share on other sites More sharing options...
cgm225 Posted February 24, 2008 Author Share Posted February 24, 2008 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 Quote Link to comment Share on other sites More sharing options...
teng84 Posted February 24, 2008 Share Posted February 24, 2008 your query failed.. try to echo your query and copy it directly on your sql... and see if you will get result Quote Link to comment Share on other sites More sharing options...
cgm225 Posted February 25, 2008 Author Share Posted February 25, 2008 That is not the problem because when I am not using that function, the query works fine. Any other ideas? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 25, 2008 Share Posted February 25, 2008 The syntax that teng84 posted is incorrect - int mysql_num_rows ( resource $result ) Quote Link to comment Share on other sites More sharing options...
cgm225 Posted February 25, 2008 Author Share Posted February 25, 2008 Thank you. However, I still do not understand why the following mysql_num_rows() does not work when I use it after the function I have included above? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.