<?php
//connect
mysql_connect("localhost", "user", "pass");
mysql_select_db("database");
$query = mysql_query("SELECT * FROM search");
if (isset($_GET['keyword'])&& $_GET['keyword'] != "") {
$keyword = mysql_real_escape_string(htmlentities($_GET['keyword']));
echo "Result";
//explode the search term
$terms = explode(" ",$keyword);
foreach($terms as $each) {
$i++;
if($i==1)
$query .= "keywords LIKE '%$each%' ";
else
$query .= "OR keywords LIKE '%$each%' ";
}
//$construct ="SELECT * FROM search WHERE $construct";
$run = mysql_query($query);
$numrows = mysql_num_rows($run);
if ($numrows==0) {
echo "Sorry, no match found for <b>$keyword</b>.</br></br>";
} else{
echo "$numrows results found !<p>";
while($numrows = mysql_fetch_assoc($run)){
$title = $numrows ['title'];
$description = $numrows ['description'];
$link = $numrows ['link'];
echo "
<div class='width: 400px;'>
<div class='title'><a href='$link'><b>$title</b></a></div>
<div class='link'>$link</div>
<div class='desc'>$description</div>
</div>
<br />
";
}
}
}
else
{
echo "Search field is empty!";
}
This is the error message I've been getting; Notice: Undefined variable: i in C:\wamp\www...
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www...
NOTE: title, description and link are from my database.

New Topic/Question
Reply



MultiQuote




|