StanLytle Posted December 15, 2007 Share Posted December 15, 2007 I'm trying to search a table to find if a person has contributed a photograph(s) that has been approved, and if so, establish a variable with a value of 0 or 1. I've tried all kinds of things, but I just don't do this stuff enough to get the hang of it. Here's the latest failed version. $sql_query = "SELECT DISTINCT MemberID FROM Photographs WHERE Approved = '1'"; $result = mysql_query($sql_query); if (MemberID == $SessionUserID) { $SetFlagName = '1' } else { $SetFlagName = '0' } It seems so easy, a caveman could do it. Thanks, Stan Quote Link to comment Share on other sites More sharing options...
papaface Posted December 15, 2007 Share Posted December 15, 2007 $sql_query = "SELECT `MemberID` FROM `Photographs` WHERE Approved = '1'"; $result = mysql_query($sql_query); list($MEMBERID) = mysql_fetch_array($result); if ($MEMBERID == $SessionUserID) { $SetFlagName = '1' } else { $SetFlagName = '0' } Should work. Although that technically won't work because you're not cycling through the records Quote Link to comment Share on other sites More sharing options...
StanLytle Posted December 15, 2007 Author Share Posted December 15, 2007 That doesn't work either, it returns Parse error: syntax error, unexpected '}' on line 4. I've had that error from other lines and the unexpected T error thing. Maybe this needs a "while" thing? Stan Quote Link to comment Share on other sites More sharing options...
papaface Posted December 15, 2007 Share Posted December 15, 2007 Well what are you trying to do? Its not going to set a new variable for each db record. Quote Link to comment Share on other sites More sharing options...
StanLytle Posted December 15, 2007 Author Share Posted December 15, 2007 When a member is loged on ($SessionUserID), I want to search thru a table (Photographs), to find if they (MemberID), has any active photos (Aproved = 1). If so, then I want to set a variable ($whatever) to 1, or if not, then $whatever=0. I want to use $whatever later on to enable additional features. Stan Quote Link to comment Share on other sites More sharing options...
papaface Posted December 15, 2007 Share Posted December 15, 2007 Then you'd do: $sql_query = "SELECT `MemberID` FROM `Photographs` WHERE Approved = '1' AND `MemberID' ='".$SessionUserID."' "; $result = mysql_query($sql_query); if (mysql_num_rows($result)>0) { $SetFlagName = '1' } else { $SetFlagName = '0' } Quote Link to comment Share on other sites More sharing options...
StanLytle Posted December 16, 2007 Author Share Posted December 16, 2007 That did the trick. Thanks. Stan 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.