nvening Posted December 22, 2007 Share Posted December 22, 2007 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>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82836-search-script-problems/ Share on other sites More sharing options...
p2grace Posted December 22, 2007 Share Posted December 22, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/82836-search-script-problems/#findComment-421300 Share on other sites More sharing options...
nvening Posted December 22, 2007 Author Share Posted December 22, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/82836-search-script-problems/#findComment-421347 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.