...

View Full Version : php/mysql search page



barkermn01
08-02-2008, 11:38 PM
i this script now it is supposed to be a search


<?php
$i = 0;
$readin = '+'.$_GET['Search'];
$words = explode("+", $readin);
$max = count($words) - 1;
while($i != $max)
{
$sql = "SELECT * FROM `pages` where `keywords` LIKE '%".$words[$i]."%' LIMIT 0,10";
$query = mysql_query($sql, $con);
while($row = mysql_fetch_array($query))
{
echo' <table width="409" border="0">
<tr>
<td><a style="color: #4A912B;" href="http://www.brook-babes.org.uk/'.$row['link'].'">BrookBabes: '.$row['title'].'</a></td>
</tr>
<tr>
<td>'.$row['Content'].'</td>
</tr>
<tr>
<td><h6>http://www.brook-babes.org.uk/'.$row['link'].'</h6></td>
</tr>
</table>';
}
$i++;
}
$row = mysql_fetch_array($query);
if($row['id'] > 10)echo 'Not found what you were looking for <br> try refining your search';
?>

but for some reason this outputs all it can from my DB even with goboldy gook in there but if i change this
$readin = '+'.$_GET['Search']; to
$readin = ''.$_GET['Search']; i dont get any results yet of the tutorials i have read it sould work can any one help please

derzok
08-03-2008, 03:27 AM
Use print_r on your array and you'll see why. You're array most likely contains an empty string. When that string is concatenated with &#37;'s on either side, you're then matching for '%%' - which is going to match everything in your database. I only know this because I fixed the very same problem in one of my scripts recently.

barkermn01
08-03-2008, 10:25 AM
ok thanks for that i will have a look

barkermn01
08-03-2008, 10:33 AM
Thanks i got it working


$i = 0;
$readin = ''.$_GET['Search'];
$words = explode("+", $readin);
$max = count($words);
while($i != $max)
{
$sql = "SELECT * FROM `pages` where `keywords` LIKE '&#37;".$words[$i]."%' LIMIT 0,10";
$query = mysql_query($sql, $con);
while($row = mysql_fetch_array($query))
{
echo' <table width="409" border="0">
<tr>
<td><a style="color: #4A912B;" href="http://www.brook-babes.org.uk/'.$row['link'].'">BrookBabes: '.$row['title'].'</a></td>
</tr>
<tr>
<td>'.$row['Content'].'</td>
</tr>
<tr>
<td><h6>http://www.brook-babes.org.uk/'.$row['link'].'</h6></td>
</tr>
</table>';
}
$i++;
}
$row = mysql_fetch_array($query);
if(isset($row['id']))echo 'Sorry we could not find a page with your keywords in it';
if($row['id'] > 10)echo 'Not found what you were looking for <br> try refining your search';
?>

barkermn01
08-03-2008, 10:48 AM
have a look at it working
http://www.brook-babes.org.uk/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum