...

View Full Version : search no results



NTGre
01-03-2006, 05:26 PM
hello Again!!!
& Happy new year to All:thumbsup:

i m trying to make a search page.
the code is.....


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<?php
include("config.inc.php");


if(isset($_GET['search']))
{
$search = $_GET['search'];
}

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

$query = "SELECT photo_id,photo_filename,photo_caption,photo_category,Gerne,First,Last,elm1,photo_category1,date_subm ited,enddate FROM gallery_photos " .
"WHERE First LIKE '%".$keywords['0']."%'";

for ($i=1; $i<count($keywords); $i++) {
$query = $query." OR First LIKE '%".$keywords[$i]."%'";
}

$result = mysql_query($query) or die(mysql_error());
?>
<center>
<form method="GET" action="search1.php">
<b>Search:</b> <input type="text" name="search" size="20" />
<input type="submit" value="Search!" />
</form>
<table width="50%" style="border:1px solid #000000;">
<?php
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td style='border-bottom: 1px solid #000000;'>";
echo "<b>".$row['photo_caption']."</b>";
echo "<p>".$row['First']."</p>";
echo "<p>".$row['Last']."</p>";
echo "<p>".$row['photo_filename']."</p>";
echo "<p>".$row['photo_category1']."</p>";
echo "<p>".$row['enddate']."</p>";
echo "<b>".$row['date_submited']."</b>";
echo "</td>";
echo "</tr>";
}
?>
</td>
</tr>
</table>
<a href="HTMLinput.htm">Add new record to our DataBank.</a>
</center>
</body>
</html>

when i first load this page i m geting all the results of my table gallery_photos
but when im using the search field i dont get any results or errors:confused:

Can any1 Help me pls????

Velox Letum
01-03-2006, 07:26 PM
Try running print_r($keywords); after $keywords = explode(" ", $search); to see if the keywords are even being split properly. Also, are you sure the 'First' field is filled in on the database?

eksob
01-03-2006, 08:09 PM
Two things you might want to look at:



if(isset($_GET['search']))
{
$search = $_GET['search'];
}


if search is not set what happens?

you should use something like


$search = $_GET['search'];
if(empty($search)){
echo "You did not search for anything!";
}else{
//your search results
}




$query = "SELECT photo_id,photo_filename,photo_caption,photo_category,Gerne,First,Last,elm1,photo_category1,date_subm ited,enddate FROM gallery_photos " .
"WHERE First LIKE '%".$keywords['0']."%'";

for ($i=1; $i<count($keywords); $i++) {
$query = $query." OR First LIKE '%".$keywords[$i]."%'";
}
I am not 100% positive, but I think that their maybe something wrong with your loop, or what was you are combining the two strings.

NTGre
01-03-2006, 09:11 PM
thnx friends..
i ll try to follow your recommendations:)

Element
01-03-2006, 09:24 PM
thnx friends..
i ll try to follow your recommendations:)

If you are doing the query like that, you might as well just input the entire search result into the query, what you need to do to search individual results would be to loop the entire query over and over. This could be annoying however, it also could give you more absolute results.

Though, MySQl has useful options to search, you might try to search with $search with something like the LIKE option in MySQL.

I'm briefly looking at this, trying to fix my rifle, I'll come back when you reply and if it isn't already solved I'll try a solution based off what you want the script to do.

Prikid
01-03-2006, 09:50 PM
Consider MySQL Fulltext (http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html) option as well



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum