StanLytle Posted May 1, 2007 Share Posted May 1, 2007 What I want to do, is search a table named "Photos", and compare the current user's ID number (logged in) with the UserID number(s) in the table. If the current user has contributed photos, I want to set a flag named $PhotoContrib = 1. Otherwise (default), if they have not contributed photos, $PhotoContrib = 0. I don't want anything to print out, I just want to set a value to use later. Here's what I have: $PhotoContribQuery = "SELECT DISTINCT UserID FROM Photos ORDER BY UserID"; $PhotoContribResult = mysql_query($PhotoContribQuery) or die(mysql_error()); while ($UserID = mysql_fetch($PhotoContribResult)) if ($SessionUserID = $PhotoContribResult) { $PhotoContrib = 1; } else { $PhotoContrib = 0; } But I get this: Fatal error: Call to undefined function: mysql_fetch() in /home/locophot/public_html/PhotoContrib.php on line 7. What am I doing wrong? Thanks, Stan Quote Link to comment https://forums.phpfreaks.com/topic/49542-query-not-working-fatal-error-undefined-function/ Share on other sites More sharing options...
papaface Posted May 1, 2007 Share Posted May 1, 2007 no such thing as mysql_fetch() its mysql_fetch_assoc() Quote Link to comment https://forums.phpfreaks.com/topic/49542-query-not-working-fatal-error-undefined-function/#findComment-242848 Share on other sites More sharing options...
StanLytle Posted May 1, 2007 Author Share Posted May 1, 2007 That fixed the fatal error. To check if the query was working correctly, I added echos: if ($SessionUserID = $PhotoContribResult) { $PhotoContrib = 1; echo "user has photos posted."; } else { $PhotoContrib = 0; echo "user does not have photos posted."; } What happens, is that it prints out a list of "user has photos posted." (which would set $PhotoContrib = 1) as it loops through the table. Since I am not logged in, I don't have a SessionUserID set, so it should at least return "user does not have photos posted.". Do I need a GET statement somewhere to fetch the current SessionUserID number to compare against the table? Thanks, Stan Quote Link to comment https://forums.phpfreaks.com/topic/49542-query-not-working-fatal-error-undefined-function/#findComment-242885 Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 I found one thing wrong with the code that you have now. if ($SessionUserID == $PhotoContribResult) { $PhotoContrib = 1; echo "User has photos posted."; } else { $PhotoContrib = 0; echo "User does not have photos posted."; } If you only put one equal sign on the first line, the code actually sets the variable to $PhotoContribResult. But since it's in an "if" statement, two equal signs means that the script will actually check if they are equal to each other. As for the session thing, read about it here. Quote Link to comment https://forums.phpfreaks.com/topic/49542-query-not-working-fatal-error-undefined-function/#findComment-242995 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.