Jump to content


Photo

search boxes in dremaweaver


  • Please log in to reply
1 reply to this topic

#1 simon0304

simon0304
  • Members
  • Pip
  • Newbie
  • 1 posts

Posted 06 December 2004 - 07:05 PM

Hi all,
I have a database for insect species. I have set up a search box which a user can enter a keyword and it pull out any info from the database containing that word. I have two problems. Firstly Everything works ok, but I have just noticed that if no entry is place in the text box and the search button is pressed then everything from the database is displayed. Is there anyway to correct this.

the script is as follows

SELECT ID, BF, Vernacular, Taxon
FROM species
WHERE Vernacular LIKE '%colname%'
ORDER BY Vernacular ASC


Hope you can help
Thanks
Simon

#2 Pilot-Doofy

Pilot-Doofy
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationMustywindows.com!

Posted 22 December 2004 - 02:00 AM

code and stuff

Try this, assuming you can change the variables accordingly.

// variable for the $_POST
$search_string = $_POST['searchfield'];

if ($search_string == "") // asking if its empty
{
echo "Sorry, please <a href=javascript:history.go(-1);>go back</a> and enter something in the search field!";
}

elseif ($search_string != "") // if its not empty, you an also use if (!empty($search_string))
{
$query = "SELECT ID, BF, Vernacular, Taxon FROM species WHERE Vernacular LIKE '%colname%' ORDER BY Vernacular ASC";
$result = mysql_query($query);
$result_total = mysql_num_rows($result); // see how many results were pulled
if ($result_total == 0) // if nothing is returned in the search do this
{
echo "Sorry, no results matched your search criteria.";
}
if ($result_total > 0) // if results are actually brought up do this
{
echo "Congratulations! There were $result_total results found matching the criteria you searched for!";
// give loop to show all the results here
}
else // if something other than that goes wrong
{
echo "There was a problem outside the magical realm of my knowledge, try again.";
}
}

mysql_close(); // close connections

Try that, sorry if its wrong in some ways, I'm studying for my History exam.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users