Jump to content

Recommended Posts

I'm trying to design a PHP search engine, everything works except the results being displayed and i can't find any problems in the script. Can someone else please look and see if there is something wrong

 

<?php
//get data
$button = $_GET['submit'];
$search = $_GET['search'];
if (!$button)
echo "You searched for <b>$search</b><hr/>";
else
{
if ($button)		
echo "You searched for <b>$search</b><hr/>";
else


{
//connect to our database
mysql_connect("localhost", "392627", "password");
mysql_select_db("392627");


$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each)

{
$x++;
if ($x==1)
$construct .= "keywords LIKE `%$search_each%`";
else
$construct .= "OR keywords LIKE `%$search_each%`";
}
}
$construct = "SELECT * FROM searchengine WHERE $construct";
$run = mysql_query($construct);

$foundnum = mysql_num_rows($run);
if ($foundnum==0)
echo "<div align='center'>Sorry, No results found</div>";
else
{
echo "<div align='center'><b>$foundnum</b> Results found! Thanks for searching with us!</div><p>";

while ($runrows = mysql_fetch_assoc($run))
{
//get data
$title = $runrows['title'];
$desc = $runrows['description'];
$url = $runrows['url'];

echo "
<b>$title</b><br>
$desc<br>
<a href='$url'>$url</a><p>
";


}
}



}
?>

Link to comment
https://forums.phpfreaks.com/topic/236372-code-problem/
Share on other sites

for starters, always use { and } even for one line if/else blocks to make it easier for people to read.

always post code here in code tags.

and read the posting guidelines about titling your post and posting to the proper forum.

("code problem" is a terrible thread name, and this is not about a 3rd party script)

Link to comment
https://forums.phpfreaks.com/topic/236372-code-problem/#findComment-1215266
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.