0
<?php
ini_set('display_errors', 0);
$search = $_GET ['search'];
mysql_connect("localhost", "root", "gokul");
mysql_select_db("search123");
$query    = mysql_query("SELECT * FROM search WHERE name LIKE '%" . $queryString . "%'");
$foundnum = mysql_num_rows($query);
if ($foundnum == 0) {
    echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.
Try more general words. for example: If you want to search 'how to create a website' 
then use general keyword like 'create' 'website'</br>2. Try different words with similar
 meaning</br>3. Please check your spelling<br/>4.PLEASE DON'T USE SPACES";
}
else {
    echo "$foundnum results found !<p>";
    $row = mysql_fetch_assoc($query);
    {
        $title = $runrows ['title'];
        $desc  = $runrows ['description'];
        $url   = $runrows ['url'];
        echo "<a href=$row[url]>$row[name]</a><br><font color=green>$row[url]</font><br>$row[desc]<br/>";
    }
}
?>

This is my search engine script. This script only show one result. How to change it to show multy results using php

1
  • you need to add loop to print your results. i.e. while Commented Mar 29, 2012 at 14:38

3 Answers 3

3

change to:

while ($row = mysql_fetch_assoc($query)) {
    $title = $runrows ['title'];
$desc = $runrows ['description'];
$url = $runrows ['url'];
echo "<a href=$row[url]>$row[name]</a><br><font color=green>$row[url]</font><br>$row[desc]<br/>";

}
Sign up to request clarification or add additional context in comments.

Comments

1

A bit more explanation for Elen's (correct) answer. mysql_fetch_assoc() fetches one record from the resultset. You can call it repeatedly to get each record in turn. Once you have fetched the last record "$row = mysql_fetch_assoc($query)" will fail. Therefore you can use that expression in your while loop to get each row and stop when you're done.

Comments

0

Here mysql_fetch_assoc you are just fetching the results, not looping them. http://php.net/manual/en/function.mysql-fetch-assoc.php

Use a foreach() or any loop method to get more results.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.