this is the index page
<?php
if (isset ($_POST['keywords'])){
$keywords =mysql_real_escape_string(htmlspecialchars(trim($_POST['keywords'])));
$keywords =$_POST['keywords'];
$errors = array ();

if (empty ($keywords)){
$errors[] = ('Please enter a serch terms');
}else if (strlen($keywords)<3){
$errors[] = ('Your search terms must be three or more characters');
}else if (search_results ($keywords) == false){
$errors []= ('Your search for '.$keywords.' returned no results');
}
if(empty($errors)) {
$results=search_results ($keywords);
$results_num = count ($results);

 echo '<p>Your search for <strong>',$keywords,'</strong>returned <strong>',$results_num,'</strong>results</p>';

}else {
foreach ($errors as $error){
echo $error,'</br>';
}
}
}


?>
and this is the func.inc.php page


<?php include('db.inc.php');


function search_results ($keywords){
$returned_results = array ();

$where = "";

$keywords = preg_split ('/[\s]+/',$keywords);
$total_keywords = count($keywords);

foreach ($keywords as $key=> $keyword){
$where .= "'keywords' LIKE '%$keyword%'";
if($key !=($total_keywords - 1)) {
$where .= " AND ";
}
}
$results ="SELECT `title`, LEFT('description',70) as `description` , `url` FROM  `articles` WHERE $where";
$results_num = ($results = mysql_query ($results)) ? mysql_num_rows($results): 0 ;

if ($results_num == 0){
return false;
}else{


while ($results_row = mysql_fetch_assoc($reults)){
$returned_results [] = array (
                       'title' => $results_row ['title'],
                       'description' => $results_row ['description'],
                       'url' => $results_row ['url']


);

}
return $returned_results;

}
}
 ?>
<?php
mysql_connect ('localhost','root','');
mysql_select_db('searchengine')


?>






the db conection

The problem is that it doesnt display what is in the database but it show no results found,help me plzz im lost now i have seen a lot of tutorial but i haven't fix this

Member Avatar for LastMitch

@andyy121

The problem is that it doesnt display what is in the database but it show no results found,help me plzz im lost now i have seen a lot of tutorial but i haven't fix this

1) Is your DB connected?
2) Can you Select:

$results ="SELECT `title`, LEFT('description',70) as `description` , `url` FROM `articles` WHERE $where";

3) If Yes, then you have data in the DB but if no, you need to learn how to Select I can't help you anymore than that.

commented: thank you for responding to my problem +0

yea it may be a probelm in the connection i have data in the db i will tray another way

Line 16 and 21 still have single quotes around keywords and description. Change them to backticks.

@pritaeas
i have donet but nothing happens have a look:


$where .= "`keywords` LIKE '%$keyword%'";


$results = "SELECT 'title' LEFT(`description`,70) as 'description' , 'url' FROM  'articles' WHERE $where";

anything else plz i have speend a lot of time doing this

Same in line 8: title, description, url and articles should be in backticks, not single quotes... and add a comma after title.

@pritaeas

$results = "SELECT `title`, LEFT(`description`,70) as `description` , `url`, FROM  `articles`, WHERE $where";


i have put  but nothing happen

@LastMitch (last of mohicans)leave me alone i wont to know where is my mistake

commented: nobody will help you with that attitude -2
Member Avatar for LastMitch

@andyy121

i wont to know where is my mistake

I think everyone has explain the mistakes to you. But you still being very rude.

Removed the comma after url (before FROM) and after articles (before WHERE).

I strongly suggest you read up on how to write correct MySQL queries, because you are making some very basic errors.

the error wasnt in the comma it show me this:
Notice: Undefined variable: reult in C:\xampp\htdocs\search\func.inc.php on line 37

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\xampp\htdocs\search\func.inc.php on line 37
Your search for facebook returned no results

Member Avatar for LastMitch

@andyy121

the error wasnt in the comma it show me this:
Notice: Undefined variable: reult in C:\xampp\htdocs\search\func.inc.php on line 37

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\xampp\htdocs\search\func.inc.php on line 37
Your search for facebook returned no results

You didn't post any errors in the first place. Everyone who has help you is base on the script you provided.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.