Ajax working, SQL Match not working - can u see why?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Ajax working, SQL Match not working - can u see why?

Post by simonmlewis »

Got a problem here with MATCH AGAINST.
This script works on another site, but not here. If I use a standard "WHERE answer LIKE '%$q%'"..... it works. But this doesn't.

I have tried so many options but cannot suss this. Can anyone see anything obviously silly that I've done?

Code: Select all

echo "<script>
function precheck(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("srcHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","/faqsearch.php?q="+str,true);
xmlhttp.send();
}
</script>

<form method='post' action='/faq' name='faqcheck'>
<input type='text' name='faq'  value='' onKeyUp=\"precheck(this.value)\">
<input type='submit' value='Search FAQs'></form><hr noshade size='1' color='#cccccc' />
<div id='srcHint' class='hintbox'></div>";

Code: Select all

<?php
$q=$_GET["q"];
include "dbconn.php";
$result = mysql_query ("SELECT * FROM faq WHERE MATCH(question,answer) AGAINST ('$q' IN BOOLEAN MODE)")or die(mysql_error());
$num_rows = mysql_num_rows($result); 
if ($num_rows == 1) { echo "<div class='sectionhead'>Does this answer your question?</div><div class='faqsearch'>";}
if ($num_rows > 1) { echo "<div class='sectionhead'>Do these answer your question?</div><div class='faqsearch'>";}
while ($row = mysql_fetch_object($result)){
echo "<b>$row->question</b><br/>$row->answer<hr noshade size='1' />";
echo mysql_error();
} mysql_free_result($result);
if ($num_rows != 0) { echo "</div>";}
mysql_close($sqlconn);
?>
Attachments
Screenshot of my DB Structure
Screenshot of my DB Structure
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Ajax working, SQL Match not working - can u see why?

Post by simonmlewis »

It does now seem to be working, but not instantly. If I start typing with words I know are in the answer field, it doesn't come up - but after more words, it does. Why?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Ajax working, SQL Match not working - can u see why?

Post by mikosiko »

drop the duplicated Indexes question_2 and answer_2 and check again
Post Reply