joshgarrod Posted June 7, 2009 Share Posted June 7, 2009 hello all. i have a poblem, i have a bar down the side of my website and it shows all of the different makes from my classified adverts and how many of them there are. the user then clicks on link and it should then only show the results matching that description. it knows how many there are when it loads the search page, however, it doesn't show any results. here is my code: <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=100; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database mysql_connect("ipaddr","usr","pass"); //(host, username, password) //specify database mysql_select_db("db") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from classifieds where make like \"%$trimmed%\" order by make"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if ($numrows == 0) { echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . "", there are $numrows caravans matching this criteria</p>"; while ($row= mysql_fetch_array($result)) { $ref = $row["ref"]; $make = $row["make"]; $model = $row["model"]; $year = $row["year"]; $berth = $row["berth"]; $weightun = $row["weightun"]; $weightla = $row["weightla"]; $lengthin = $row["lengthin"]; $lengthex = $row["lengthex"]; $image1 = $row["image1"]; $price = number_format($row["price"]); //formatting the price field to use a thousand separator echo '$berth'; echo "<div id=\"caravan_row\">"; echo "<div id=\"logo\"><a href='view_used_caravan.php?ref=$ref'><img src=\"images/$make.gif\" border=\"0\" alt=\"$make caravan\" title=\"$make caravan\" width=\"66\" height=\"83\"/></a></div>"; if ($image1 == "uploads/") { echo "<div id=\"image\"><a href=\"view_used_caravan.php?ref=$ref\"><img src=\"images/icon_no_photo.gif\" alt=\"$make $model $year\" width=\"100\" height=\"75\" border=\"0\" /></a></div>"; } else { echo "<div id=\"image\"><a href='view_used_caravan.php?ref=$ref'><img src=\"$image1\" border=\"0\" alt=\"$make $model $year\" width=\"100\" height=\"75\" title=\"$make $model $year\" /></a></div>"; } echo "<div id=\"specifications\">"; echo "<div id=\"make\"><h1></strong>$make $model</h1></div>"; echo "<div id=\"price\"><span class=\"price\">£$price</span></div>"; echo "<div id=\"more\"><a href='view_used_caravan.php?ref=$ref' title=\"More info on the $make $model $year \">More info>></a></div>"; echo "<div id=\"year\"><strong>Year: </strong>$year</div>"; echo "<div id=\"weightun\"><strong>MIRO: </strong>$weightun kg</div>"; echo "<div id=\"berth\"><img src=\"images/$berth.gif\" class=\"berth\" />$berth berth</div>"; echo "<div id=\"weightla\"><strong>MTPLM: </strong>$weightla kg</div>"; echo "<div id=\"lengthex\"><strong>Shipping length: </strong>$lengthex ft</div>"; echo "<div id=\"lengthex\"><strong>Location: </strong>$county</div>"; echo "</div>"; echo "</div>"; } ?> many thanks in advance Link to comment https://forums.phpfreaks.com/topic/161299-refine-search-results/ Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 You can just run the SQL once - SELECT * FROM classified WHERE make LIKE '%{$trimmed}%' ORDER BY make LIMIT {$s}, {$limit}; That will do the same thing except you don't have to run a SQL twice. Check to make sure the SQL returned results before the while loop. Same as you did in the first case. If you use my query up there, check to make sure it returns at least 1 row. Link to comment https://forums.phpfreaks.com/topic/161299-refine-search-results/#findComment-851195 Share on other sites More sharing options...
joshgarrod Posted June 8, 2009 Author Share Posted June 8, 2009 How do you mean? I just replaced the query line and all I get again is an error. It seems to be finding the results but it won't display them. It prints a message saying how many there are? Link to comment https://forums.phpfreaks.com/topic/161299-refine-search-results/#findComment-851402 Share on other sites More sharing options...
joshgarrod Posted June 8, 2009 Author Share Posted June 8, 2009 does anyone else know what my problem is here please? Link to comment https://forums.phpfreaks.com/topic/161299-refine-search-results/#findComment-851588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.