I’m working on a website to try and learn coding and am making a simple search site.
When the user searches for either “Restaurant” or “Restaurants” (or some other words but I’m just using these as examples), a list of words that could help refine the search such as “American Food” or “Chinese Food” appears. But there is quite a few refining words to choose from so I stored all of them in a database, and am using Javascript to display more ( when you first go there is a limit of 10 refining words on the page but when you click see more the rest appear.) Anyways, I thought that I would do a mysql select to show rows 1-10 and then another mysql select for rows 11 to the end of all the rows in the div that is not displayed until the user clicks see more. But I keep getting this error
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Users/searchswitch.php on line 17
Warning: mysql_close(): 4 is not a valid MySQL-Link resource in /Users/searchswitch.php on line 22
What is causing this? Also, I know (even being a new programmer) that my code is not very clean, how can I clean this up)
Here’s the code: I left out the other switch cases to make it easier to read but if you need any more info, I’ll be glad to help! Thanks for all help!
switch ($q) {
case "Restaurants" || "Restaurant":
echo "<hr /><span><strong>Refine Search</strong><br/><br/>";
$result = mysql_query("SELECT * FROM subcat WHERE catnumber='1' LIMIT 0,10");
while($row = mysql_fetch_array($result))
{
echo "<a href='search.php?q=". $row['subcat'] ."'/>" . $row['subcat'] ."</a>";
echo "<br />";
}
mysql_close($link);
echo "<a href='#' id='example-show' class='showLink' onclick='showHide(\"example\");return false;'><br/>See more</a></span><div id='example' style='display:none;'>";
$result = mysql_query("SELECT * FROM subcat WHERE catnumber='1' LIMIT 11,100");
while($row = mysql_fetch_array($result))
{
echo "<a href='search.php?q=". $row['subcat'] ."'/>" . $row['subcat'] ."</a>";
echo "<br />";
}
mysql_close($link);
echo"<br/><a href='#' id='example-hide' class='hideLink' onclick='showHide(\"example\");return false;'>Hide</a></div>";
break;
Oh also want to point out that line 17 is *while($row = mysql_fetch_array($result))* and line 22 is *mysql_close($link);*
Use this your query will work fine