开发者

autocomplete query to execute another mysql query if rows = 0 on first one using last keyword entered

I'm working on a type of spellcheck, autosuggest. I have two dictionarie开发者_如何转开发s, one with phrases, and one that should kick in for basic spelling suggestions. Right now I have this on the server side:

 $q = strtolower($_GET["q"]);
$q= mysql_real_escape_string($q);
if (!$q) return;

$sql = ("SELECT headings FROM dictionary WHERE headings LIKE '$q%' LIMIT 3");
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
    $auto = $rs['headings'];
    echo "$auto\n";

}
if (mysql_num_rows(mysql_query("SELECT headings FROM dictionary WHERE headings LIKE '$q%' LIMIT 3")) == 0){
    $res = mysql_query("SELECT spelling FROM spellcheck WHERE spelling LIKE '$s%' LIMIT 3");
        while($result = mysql_fetch_array($res)) {
            $spell = $result['spelling'];
            echo "$spell\n";
        }
    }

basically, $s should equal where the first query left off. So if the query was : hello wor. $s would be wor and it would suggest "world" from the mysql_query: $res. I would have to deal with multiple spaces between words too.


Use mysql_affected_rows() to get affected rows of last executed query...

refer http://php.net/manual/en/function.mysql-affected-rows.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜