kadamsurekha Posted March 27, 2007 Share Posted March 27, 2007 hello friends! i have the table with fields:- ID,username,friendname,status where status can be 1 or 2 now i want the query to execute such that it retrieves the data where the string passed can be either in username or in friendname with status 2 only. i hav written the code in php file as follows:- $username=$_POST['emailid']; $result = mysql_query("SELECT username,friendname FROM friendlist where username='$username' or friendname='$username' and status=2"); after execution i get records from the table where $username exists in username or friendname field but with any status. i want records where status is only 2 and $username exists in username or friendname field. thx n regards Link to comment https://forums.phpfreaks.com/topic/44491-select-statements-in-php-mysql/ Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 Basic math, order of operations. Try this: $username=$_POST['emailid']; $result = mysql_query("SELECT username,friendname FROM friendlist where (username='$username' or friendname='$username') and status=2"); Need parenthesis. Link to comment https://forums.phpfreaks.com/topic/44491-select-statements-in-php-mysql/#findComment-216085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.