0
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>';
}
}
}


?>
3
Contributors
16
Replies
17
Views
4 Years
Discussion Span
Last Post by LastMitch
Featured Replies
  • **@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 … Read More

  • 2

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

  • **@andyy121** > i wont to know where is my mistake I think everyone has explain the mistakes to you. But you still being very rude. Read More

  • 2

    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. Read More

0
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;

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


?>






the db conection
0

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

2

@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.

Votes + Comments
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

2

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

0
@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";
0

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

0

@pritaeas

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


i have put  but nothing happen
-4

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

Votes + Comments
nobody will help you with that attitude
2

@andyy121

i wont to know where is my mistake

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

2

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.

Edited by pritaeas

-1

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

0

@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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.