andyd34 Posted March 9, 2009 Share Posted March 9, 2009 I have a column in a database which i want to fetch 2 differing values from depending on the access rights of a member. I have used $countRes = mysql_query('SELECT * FROM table WHERE user = "'.$member.'"') or die(mysql_error()); $count=mysql_num_rows($countRes); if(empty($count)) { $file_stat[1] = 'public'; } else { $file_stat[1] = 'public'; $file_stat[2] = 'friends'; } mysql_free_result($countRes); $result = mysql_query('SELECT * FROM table WHERE user = "'.$member.'" AND fileStatus IN("'.implode('", "', $file_stat).'")') or die(mysql_error()) This has worked for me before but doesn't seem to be working this time. Does anyone have a suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/ Share on other sites More sharing options...
ngreenwood6 Posted March 10, 2009 Share Posted March 10, 2009 Are you getting an error or what isnt working? It usually helps if you give information on what is or is not happening that is supposed to or not supposed to. Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-780796 Share on other sites More sharing options...
andyd34 Posted March 10, 2009 Author Share Posted March 10, 2009 When the user isn't veryfied its showing public results only and when they are verifified it's only showing public results. I have added the following if(empty($count)) { $file_stat[1] = 'public'; echo 'Unverified'; } else { $file_stat[1] = 'public'; $file_stat[2] = 'friends'; echo 'Verified'; } When not logged in it shows public files and echoes unverified When logged in it echoes verified and only shows public files. There are no errors or warnings, if you didn't know better you'd think it was working fine Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781135 Share on other sites More sharing options...
ngreenwood6 Posted March 10, 2009 Share Posted March 10, 2009 I have never used the fileStatus IN mysql but could it be because it is being called after you are trying to use the variables? Could you move the line before the if/else statement? Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781140 Share on other sites More sharing options...
andyd34 Posted March 10, 2009 Author Share Posted March 10, 2009 the "fileStatus" is a column in the database which hold information whether a file is for public viewing for friends viewing only. Basically what it is, is SELECT & FROM table WHERE file_is_either IN("public, friends") I cannot find anything on the mysql 'IN' function and was hopeing someone could assist Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781256 Share on other sites More sharing options...
kickstart Posted March 10, 2009 Share Posted March 10, 2009 Hi That would be:- SELECT & FROM table WHERE file_is_either IN("public", "friends") All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781268 Share on other sites More sharing options...
sasa Posted March 10, 2009 Share Posted March 10, 2009 try $result = mysql_query("SELECT * FROM table WHERE user = '".$member."' AND fileStatus IN('".implode("', '", $file_stat)."')") or die(mysql_error()); swap single and double quotes Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781304 Share on other sites More sharing options...
ngreenwood6 Posted March 10, 2009 Share Posted March 10, 2009 Sasa are you using [ code ] tags or [ php ] tags because I can only see a horizontal scroll bar on this one too. Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781326 Share on other sites More sharing options...
Philip Posted March 10, 2009 Share Posted March 10, 2009 Sasa are you using [ code ] tags or [ php ] tags because I can only see a horizontal scroll bar on this one too. that's the php tag Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781331 Share on other sites More sharing options...
ngreenwood6 Posted March 10, 2009 Share Posted March 10, 2009 oh ok you might want to use the code tags then because i havent been able to read any of your posts lol edit: OP sorry for interrupting. Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781341 Share on other sites More sharing options...
sasa Posted March 10, 2009 Share Posted March 10, 2009 try $result = mysql_query("SELECT * FROM table WHERE user = '".$member."' AND fileStatus IN('".implode("', '", $file_stat)."')") or die(mysql_error()); swap single and double quotes report error to administrator Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781349 Share on other sites More sharing options...
andyd34 Posted March 10, 2009 Author Share Posted March 10, 2009 Thanks for all the replies, they're much appreciated but none worked. Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781440 Share on other sites More sharing options...
andyd34 Posted March 10, 2009 Author Share Posted March 10, 2009 I am really sorry to mess everyone around who took the time to read this post but both $result = mysql_query("SELECT * FROM table WHERE user = '".$member."' AND fileStatus IN('".implode("', '", $file_stat)."')") or die(mysql_error()); and $result = mysql_query('SELECT * FROM table WHERE user = "'.$member.'" AND fileStatus IN("'.implode('", "', $file_stat).'")') or die(mysql_error()) work fine, the trouble was there is a third setting in the fileStatus table (private), there where no friends just public and private so that's where it was going wrong/right. Aparently it was the idiot on the keyboard that was coding it that was the error Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781526 Share on other sites More sharing options...
sasa Posted March 10, 2009 Share Posted March 10, 2009 i tell that swap quotes because "If the ANSI_QUOTES SQL mode is enabled, string literals can be quoted only within single quotes because a string quoted within double quotes is interpreted as an identifier." (from mysql manual) Quote Link to comment https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781547 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.