Page 1 of 1

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

Posted: Thu May 03, 2012 4:53 am
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);
?>

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

Posted: Thu May 03, 2012 5:04 am
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?

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

Posted: Thu May 03, 2012 5:43 am
by mikosiko
drop the duplicated Indexes question_2 and answer_2 and check again