Jump to content

Search engine results page problem


boba fett

Recommended Posts

My search engine is working beautifully to find the things that we want it to find. Problem is that when the results are displayed it displays the name, scientific name and common name for each returned entry. I would like to know how to get the titles to be displayed only once on the top of the page.

 

 

 <HTML>

      <title>Search Engine</title>

<form action='search.php' method='GET'>

          <font face='sans-serif' size='5'>

          <center>

                  My Search Engine.<br />

                  <input type='text' size='50' name='search' /><input type='submit' name='submit' value='Search' /><br />

 

          </center>

          </font>

       

    </form>

</HTML>

 

 

 

<?php

 

//get data

$button = $_GET['submit'];

$search = $_GET['search'];

 

if (!$button)

echo "You didn't submit a keyword.";

else

{

if (strlen($search)<=2)

 

echo "Search not valid. Search term too short.";

else

{

echo "You searched for <b>$search</b> <hr size='1'>";

 

//connect to our database

mysql_connect("localhost:8888","root","root");

mysql_select_db("snakebook");

 

 

{

//explode our search term

$search_exploded = explode(" ",$search);

 

foreach($search_exploded as $search_each)

{

 

//construct query

$x++;

if ($x==1)

$construct .="Scientific_Name LIKE '%$search_each%'

OR Common_Name LIKE '%$search_each%'

OR Physical_Characteristics LIKE '%$search_each%'

OR Geographic_Range LIKE '%$search_each%'

OR Diet LIKE '%$search_each%'

OR Venom LIKE '%$search_each%'

OR Habitat LIKE '%$search_each%'

OR Notes LIKE '%$search_each%'

";

 

else

$construct .="  OR Scientific_Name '%$search_each%'

OR Common_Name LIKE '%$search_each%'

OR Physical_Characteristics LIKE '%$search_each%'

OR Geographic_Range LIKE '%$search_each%'

OR Diet LIKE '%$search_each%'

OR Venom LIKE '%$search_each%'

OR Habitat LIKE '%$search_each%'

OR Notes LIKE '%$search_each%'

";

 

}

 

//echo out construct

 

$construct = "SELECT * FROM specieslist WHERE $construct";

$run = mysql_query($construct);

$foundnum = mysql_num_rows($run);

 

if ($foundnum==0)

echo "No results found.";

else

{

 

echo "<b>$foundnum</b> result(s) found.<p><hr size='1'>";

while ($runrows = mysql_fetch_assoc($run))

 

 

{

//get data to display

 

echo "<center><table border='0' cellpadding='5' cellspacing='0'>

<tr>

<td><strong>Thumbnail</strong></td>

<td><strong>Scientific Name</strong></td>

<td><strong>Common Name</strong></td>

<td><strong>View/Edit</strong></td>

</tr>";

 

$common = $runrows['Common_Name'];

$scientific = $runrows['Scientific_Name'];

$thumbnail = $runrows['Thumbnail'];

 

//display data

 

echo "<tr>

<td><strong>$thumbnail</strong></td>

<td><strong><i>$scientific</i></strong></td>

<td><strong>$common</td></strong>

<td><strong>

</tr>";

 

}

 

}

}

 

}

 

}

?>[/ php]

Link to comment
https://forums.phpfreaks.com/topic/207535-search-engine-results-page-problem/
Share on other sites

If you move this

 

while ($runrows = mysql_fetch_assoc($run))

 

to just beneath this

 

<td><strong>View/Edit</strong></td>

</tr>";

 

You should be good to go, with one other minor fix. This line : <td><strong> (it's the second to last line with any html in it) needs the closing </strong> and </td> tags added.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.