-1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php include 'func.inc.php'; ?>
<title>SEARCH</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<h2>SEARCH</h2>
<form action="" method="post">
<p>
<input type="text" name="keywords"/> <input  type="submit" value="Search"/>
</p>
</form>
<?php
if (isset ($_POST['keywords'])){
$suffix ="";
$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);

$suffix = ($results_num!=1) ? 's' : '' ;

 echo '<p>Your search for <strong>', $keywords, '</strong> returned <strong>', $results_num, '</strong> result', $suffix, '</p>';
foreach ($results as $result) {

echo '<p><strong>', $result ['title'], '</strong> <br> ', $result['description'], '... <br> <a href="',$result['url'],'"target="_blank">',$result['url'],'</a></p>';

}

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


?>

</body>
</html>
4
Contributors
13
Replies
15
Views
5 Years
Discussion Span
Last Post by LastMitch
Featured Replies
  • **@andyy121** You really need to learn how to connected to the database. I'm bit tired reading this code. If you keep posting the same the code most likely no one will help you. You have to pay attention what other member give you suggestion and advice. It seems you just … Read More

  • 3

    **@andyy121** >@LastMitch aahhahhahahahaha you are such a big fail the problem wasnt in SELECT ect ect >Good Luck, I don't know what else to say.THIS IS FOR YOUUUUUUUUUUUUUUUU And that is how you treat people who try and help. Mate you are a sad person. Shooting people down that try … Read More

-1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php

$connect =mysql_connect ('localhost','root','')or die("Error connecting to SQL");
mysql_select_db('searchengine')or die("Error selecting database");
?>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>


</body>
</html>
-1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?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;

}
}
 ?>
</body>
</html>
4

@andyy121

You really need to learn how to connected to the database.

I'm bit tired reading this code. If you keep posting the same the code most likely no one will help you. You have to pay attention what other member give you suggestion and advice. It seems you just ignore everyone's suggestion and advice. Noone is gonna help you if you don't give any effort. I feel you are not trying enough, you are just waiting for answers.

You need to understand and learn how to "Select" from database. An another thing I notice is this your code that you wrote or someone else's code that you are using and trying to figure it out?

Votes + Comments
well said :)
-3

im traying to learn ok if i know where is the problem i will learn from my mistake if all of you are tired i is not my problem,if you know where is the problem i I would ask to help me i wont to learn where is the problem here if i wont to learn alone,i can not learn alone becouse i dont know a lot of things sorry for everything.

0

@andyy121

im traying to learn ok if i know where is the problem i will learn from my mistake if all of you are tired i is not my problem,if you know where is the problem i I would ask to help me i wont to learn where is the problem here if i wont to learn alone,i can not learn alone becouse i dont know a lot of things sorry for everything.

I guess English is not your first language. My advice right now learn:

http://www.w3schools.com/php/php_mysql_connect.asp

and this:

http://www.w3schools.com/php/php_mysql_select.asp

Good Luck, I don't know what else to say.

0

Hi. your 'db.inc.php' only needs the php block in it. It doesn't need all the html in there.
So all that should be in that file is:

<?php
    $connect = mysql_connect ('localhost','root','') or die("Error connecting to  SQL");
    mysql_select_db('searchengine') or die("Error selecting database");
?>

*Note i have also added a space between your closing bracket ")" and the "or" statments.

Other than that. are you getting any specific errors when you run it in the browser. If so post the error.

0

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

on your mysql_fetch_assoc,(Line 35 above) you have spelt $results as $reults. (you missed an 's' out. that would explain both the warning and the notice.

3

@andyy121

@LastMitch aahhahhahahahaha you are such a big fail the problem wasnt in SELECT ect ect

Good Luck, I don't know what else to say.THIS IS FOR YOUUUUUUUUUUUUUUUU

And that is how you treat people who try and help. Mate you are a sad person. Shooting people down that try and help. Good luck with your coding issues and trying to get help from people.

TWAT

Votes + Comments
I agree
3

@andyy121

Arguments with other members aside, did correcting the spelling mistake solve the issue?

P.S remember. People who post answers on here are usually IT proffesionals that would normally charge a small fortune for the type of consultancy provided in here. yet they do it here for free. This can sometimes be a bit of trial and error which means people will sometimes give the wrong answer but not intentionally.

Votes + Comments
Right on Target!
0

@andyy121

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 never post any errors at all

@LastMitch aahhahhahahahaha you are such a big fail the problem wasnt in SELECT ect ect

http://www.w3schools.com/php/php_mysql_connect.asp

and this:

http://www.w3schools.com/php/php_mysql_select.asp

Good Luck, I don't know what else to say.THIS IS FOR YOUUUUUUUUUUUUUUUU

Well Good Luck to You.

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.