live search with Jquery

Posted by user272899 on Stack Overflow See other posts from Stack Overflow or by user272899
Published on 2010-03-23T22:00:43Z Indexed on 2010/03/23 22:03 UTC
Read the original article Hit count: 308

Filed under:
|
|
|

Hello! I am trying to implement a live search on my site.

I am using a script somebody has already created. http://www.reynoldsftw.com/2009/03/live-mysql-database-search-with-jquery/

I have got the Jquery, css, html working correctly but am having troubles with the php.

I need to change it to contain my database information but everytime I do I recieve an error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\search.php on line 33

These are the details of my database:

database name: development

table name: links

Columns: id, sitename, siteurl, description, category

This is the php script

<?php

$dbhost = "localhost";
$dbuser = "root";
$dbpass = "password";
$dbname = "links";

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
mysql_select_db($dbname);

if(isset($_GET['query'])) { $query = $_GET['query']; } else { $query = ""; }
if(isset($_GET['type'])) { $type = $_GET['type']; } else { $query = "count"; }

if($type == "count")
{
    $sql = mysql_query("SELECT count(url_id) 
                                FROM urls 
                                WHERE MATCH(url_url, url_title, url_desc)
                                AGAINST('$query' IN BOOLEAN MODE)");
    $total = mysql_fetch_array($sql);
    $num = $total[0];

    echo $num;

}

if($type == "results")
{
    $sql = mysql_query("SELECT url_url, url_title, url_desc 
                                FROM urls 
                                WHERE MATCH(url_url, url_title, url_desc)
                                AGAINST('$query' IN BOOLEAN MODE)");
    while($array = mysql_fetch_array($sql)) {

        $url_url = $array['url_url'];
        $url_title = $array['url_title'];
        $url_desc = $array['url_desc'];

        echo "<div class=\"url-holder\"><a href=\"" . $url_url . "\" class=\"url-title\" target=\"_blank\">" . $url_title . "</a>

    <div class=\"url-desc\">" . $url_desc . "</div></div>";

    }

}

mysql_close($conn);

?>

Can anybody help me input this database info correctly? I have tried many times but keep getting an error. Thanks in advance.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql