fife Posted July 9, 2012 Share Posted July 9, 2012 ok i have a query that searches the database for members by forename, surname, school name. It works fine at the level below $result = $_POST['searchfield']; mysql_select_db($dbcon, $db); $query_rs_officers = sprintf("SELECT members.*, schools.* FROM members INNER JOIN schools ON schools.idschools = members.school WHERE ((members.mfirstname LIKE '$result') OR (members.mlastname LIKE '$result') OR (schools.schoolname LIKE '$result'))"); $rs_officers = mysql_query($query_rs_officers, $dbcon) or die(mysql_error()); $row_rs_officers = mysql_fetch_assoc($rs_officers); thats great but only if you search by actual name. Lets say the user was david. If you search david you get a result if you search da then you get nothing. I then read about opperators and changed my query to below $result = $_POST['searchfield']; mysql_select_db($dbcon, $db); $query_rs_officers = sprintf("SELECT members.*, schools.* FROM members INNER JOIN schools ON schools.idschools = members.school WHERE ((members.mfirstname LIKE '%$result%') OR (members.mlastname LIKE '%$result%') OR (schools.schoolname LIKE '%$result%'))"); $rs_officers = mysql_query($query_rs_officers, $dbcon) or die(mysql_error()); How ever this is saying my query is empty. can anyone help? thanks Link to comment https://forums.phpfreaks.com/topic/265425-search-results-error/ Share on other sites More sharing options...
Pikachu2000 Posted July 9, 2012 Share Posted July 9, 2012 Enable error reporting and see what errors are generated. Link to comment https://forums.phpfreaks.com/topic/265425-search-results-error/#findComment-1360266 Share on other sites More sharing options...
fife Posted July 9, 2012 Author Share Posted July 9, 2012 ok i get this error Warning: sprintf(): Too few arguments in /home/sites/results-members.php on line 113 Query was empty which is the query above on that line Link to comment https://forums.phpfreaks.com/topic/265425-search-results-error/#findComment-1360267 Share on other sites More sharing options...
Barand Posted July 9, 2012 Share Posted July 9, 2012 You are using sprintf, so you need to escape the %s . Use "LIKE '%%$result%%' Link to comment https://forums.phpfreaks.com/topic/265425-search-results-error/#findComment-1360268 Share on other sites More sharing options...
fife Posted July 9, 2012 Author Share Posted July 9, 2012 Solved barand and pikachu2000 thank you both Link to comment https://forums.phpfreaks.com/topic/265425-search-results-error/#findComment-1360269 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.