Question:
Help with PHP / MySQL search function?
Andrew
2011-05-29 08:45:00 UTC
I have followed around 5 separate tutorials for this who all claim their method works I copy it to a T but it never works for me and its starting to annoy me.

$sql = mysql_query("SELECT * FROM $table_1989 WHERE'Meta Tags' LIKE'%$search%'");

while($result = mysql_fetch_array($sql))
{
echo $result['Language'];
echo $result['Header'];
echo $result['Introduction'];
}
$matches = mysql_num_rows($sql);
if($matches == 0)
{
echo "

Sorry we couldn't find any matches for your search

";
}

Problem with it is the code doesn't error at all it just doesn't work either. The only difference is between mine and their tutorial is the WHERE part of the SELECT function I have to use single quotes
other wise PHP throws an error up but yet they don't use them so how come it works for them without the quotes yet mine is throwing up errors if I don't use them.

Usually because I have been staring at it for hours code that is in general not just this one. I tend to over look certain things so I'm hoping new eyes may spot an error I have made or something.

Any help would be appreciated here thanks.
Three answers:
Toad
2011-05-29 09:37:59 UTC
Try this as your query string:



"SELECT * FROM ".$table."_1989 WHERE \"Meta Tags\" LIKE \"%".$search."%\""
renard
2017-02-23 08:48:27 UTC
i might chop up the string into phrases (utilising the Hypertext Preprocessor explode() function), and then seek each and each word in the process the database. If somebody is named "stay" or "the place" then you definately could get numerous suggestions, despite the fact that if it may artwork ok. $question = "the place does adam stay?"; // certainly get this from the enter section $phrases = explode($question, ' '); // explode the variable string "$question" by utilising areas $effect = mysql_query("pick * FROM tablename the place call = '$phrases[0]' OR call == '$phrases[a million]' "); .... etc.
rooker
2016-12-05 06:57:58 UTC
i might cut up the string into words (using the very own living house page explode() function), and then seek each word in the time of the database. If somebody is termed "stay" or "the place" then you definately might get diverse recommendations, regardless of if it is going to artwork ok. $question = "the place does adam stay?"; // easily get this from the enter section $words = explode($question, ' '); // explode the variable string "$question" by potential of areas $effect = mysql_query("go with * FROM tablename the place call = '$words[0]' OR call == '$words[a million]' "); .... etc.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...