Jump to content

Search script problems


nvening

Recommended Posts

Hi, im working on a search script to search a mysql table. Im working on the basics atm and obv alot more needs to be added to this but im just trying to get this to work first! Ive adapted it from a tutorial however im confused as to where the $row has been set, this is infact causing an error of

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/site.co.uk/public_html/search.php on line 34
( line 34 is while($row = MySQL_fetch_array($rest)) { )

 

Can anyone help me :) ??

 

Heres the code, thanks!

 

<?php
$c = $_GET["c"];
    /* call this script "search.php" */
    if ($c != 1) {
?>

<form action="search.php?c=1">
<input type="text" name="keyword">
<input type="submit" value="Search!">
</form>

<?
    } else if ($c==1) {

$keyword = $_GET["keyword"];

$username = "-";
$password = "-";
$database = "-";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

        $sql = "
            SELECT *
                MATCH(name, overview, description, cusine, eatin, takeaway) AGAINST('$keyword') AS score
                FROM resturants
            WHERE MATCH(name, overview, description, cusine, eatin, takeaway) AGAINST('$keyword')
            ORDER BY score DESC
        ";

        $rest = MySQL_query($sql);

        while($row = MySQL_fetch_array($rest)) {
            echo "<tr><td>{$sql2['score']}</td>";
            echo "<td>{$sql2['name']}</td>";
            echo "<td>{$sql2['overview']}</td></tr>";
        }
}

?> 

Link to comment
Share on other sites

Here's how I'd write a simple search query

 

$query = "SELECT * FROM `db` WHERE `field1` LIKE '%$search_str%'";
$run = mysql_query($query);
while($arr = mysql_fetch_assoc($run)){
extract($arr);
echo "$field1";
}

 

You can add whatever fields you want to search for into the query.  But that is a very simple demonstration of what you need.

Link to comment
Share on other sites

Hi, thats for the reply.

 

 

The method i'm trying to use utilizes the fulltext search feature which sorts out the ranking bringing other features which make it more powerful and practice than just using like.

 

Should i try and get this script working or is it probably best to start over??

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.