Jump to content

search results error


fife

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.