• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Search script

cheatpark

­
NLC
I posted about this before but I didn't quite seem to get it working.

Below is the code I am using:

PHP:
<?
include("config.php");
include("common.php");
if($mode == "enter") {
?>
<form action=search.php>
<input type=hidden name=mode value=results>
<table width=100%>
<tr><td><input type=text name=searchtext></td></tr>
<tr><td><input type=submit value=Search></td></tr>
</form>
<?
}
$result = mysql_query("SELECT * FROM arenatopics");
while ($row = mysql_fetch_array($result)) {
if($mode == "results" && eregi($searchtext, $row[Name])) {
?>
<table width=100%>
<tr><td>Page name: <a href=view.php?ID=<? echo $row[ID]; ?>><font><? echo $row[Name]; ?></font></a></td></tr>
</table>
<?
exit;
}
}
if(eregi($searchtext, $row[Name]) !== $searchtext) {
echo "No results were found.";
}
?>

Its basically a script I am using to search my site but the problem is it will only display one result when I search for something. I tried using in_array and some other commands but they haven't worked either. For example, in the database there would be a few rows with the word php in them. Lets say there are 2 rows to make it simple. These are:

php
php > tutorials

If the user types in php it will display php but not php > tutorials. I've tried many things to solve this problem and it is driving me mad. I would appreciate any help. Thanks in advance.
 
try this


PHP:
$result = mysql_query("SELECT * FROM arenatopics");
while ($row = mysql_fetch_assoc($result)) {
extract($row);

if($mode == "results" && eregi($searchtext, $Name)) {
?>
<table width=100%>
<tr><td>Page name: <a href=view.php?ID=<? echo $ID; ?>><font><? echo $Name; ?></font></a></td></tr>
</table>
<?
exit;
}
}
if(eregi($searchtext, $Name) !== $searchtext) {
echo "No results were found.";
}
?>
 
why not do this instead:
PHP:
$query = "select * from arenatopics where Name LIKE \"%$seachtext%\"";
$result = mysql_query($query) or die(mysql_error());

if(!rows = mysql_num_rows($result)){
echo "Failed"
exit();
}
while ($row = mysql_fetch_array($result)){
 extract($row);
?>
<table width=100%>
<tr><td>Page name: <a href=view.php?ID=<? echo $ID; ?>><font><? echo $Name; ?></font></a></td></tr>
</table>
<?
 
Back
Top