UK Webmaster Talk - Online Marketing - SEO


 

I'm having a problem with my search engine!

This is a discussion on I'm having a problem with my search engine! within the Php and MySQL forums, part of the Programming / Scripting / Coding category; Hi, I've been building a search engine for my works website which will enable people to search for articles that ...


Go Back   UK Webmaster Talk - Online Marketing - SEO > Website Design & Development > Programming / Scripting / Coding > Php and MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Notices

Reply

 

LinkBack Thread Tools Display Modes
Old 01-03-2007, 15:52   #1 (permalink)
Newbie
 
Join Date: Mar 2007
Posts: 12
iTrader: 0 / 0%
ShaunBurden is an unknown quantity at this point
Default I'm having a problem with my search engine!

Hi, I've been building a search engine for my works website which will enable people to search for articles that are stored in a mysql database. Now, I don't have alot of knowledge of php and mysql, but I've learned quite a bit over the last couple months which has enabled me to build the search engine.

So far I've got a working search that will bring in the articles based on what word is typed into the search box, and it will get it from the database and put it into a page. All tha works fine, there are just a few smaller things that I need sorted out before I can continue.

1) I would like to know how I could have a search box, that also functions as a drop down menu. It would have a list of categories, but you could also click in and type in whatever you like, kinda the way the Google tool bar works, but the categories would be preset, not words that you had already typed in. Is this possible to do.

2) Here's the other thing. I'm not sure how to explain this but I'll try. I've got a php script which does all the searching and brings in the links to the articles and lays them out on the page. My page has a table on it which is split into 2 columns, and the code is in the one on the left. Now, when I view the page in the browser it doesn't show the column on the right, it just deletes it altogether. So, I'm wondering if there's something in my php code that prevents it from showing the other column. The strange thing is that it will once the search has been done and the links to the articles come up, but not before. It also won't show up anything that is below the code, as in the same way as with the right hand column.

Here's my code so that if there's anything that would cause this it can be shown.

PHP Code:
$var = @$_GET['q'] ;
$trimmed trim($var);

$host "---";
$db_name "---";
$db_user "---";
$db_pass "---";
$db_table "articles"
mysql_connect($host$db_user$db_pass);
mysql_select_db($db_name);

$field_to_search "header";
$field_to_search2 "text";
$field_to_search3 "category";
$query "SELECT * FROM $db_table WHERE $field_to_search LIKE \"%$trimmed%\" OR
$field_to_search2 LIKE \"%$trimmed%\" OR $field_to_search3 LIKE \"%$trimmed%\" order by id"
;
$result mysql_query($query); 
$count mysql_numrows($result);

if (
$trimmed == "")
{
echo 
"<p>Please enter a search...</p>";
exit;
}
if (!isset(
$var))
{
echo 
"<p>We dont seem to have a search parameter!</p>";
exit;
}
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
if (
$numrows == 0)
{
echo 
"<h4>Articles</h4>";
echo 
"<p>Sorry, your search for " .$trimmed" returned zero results</p>";
}
if (empty(
$s))
{
$s=0;
}
$result mysql_query($query) or die("Couldn't execute query");
if(
$numrows 1){ $return "results";}
else{ 
$return "result"; }

$count $s ;

while (
$rmysql_fetch_array($result))
{
$id $r["id"];
$header $r["header"];
$text $r["text"];
$image $r["image"];
$excerpt $r["excerpt"];

$count++ ; 
?><a href="http://www.pwamm.com/articles.php?id=<? echo $id ?>"><br />
</a> <a href="http://www.pwamm.com/articles.php?id=<? echo $id ?>"><? echo $header ?></a><br />
<? echo $excerpt ?><br />
<? } ?>

This is the entire code, it's split up a bit at the end. If anyone knows if I could write this in a better way I'm open to improvements, but my 2 issues are crucial just now.

Thanks for any help.
ShaunBurden is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-03-2007, 08:33   #2 (permalink)
Moderator
 
Join Date: Mar 2005
Location: Barnsley, UK
Posts: 1,001
iTrader: 0 / 0%
Wistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond repute
Default

If you simply put the above code into the left column of the table it should work how you want with regards to the right column.

As for the drop down box you'd need to add the drop down to the same form which handles the search:
Code:
<select name="category">
<option value="" selected="selected"></option>
<option value="sport">Sport</option>
</select>
Then change:
Code:
$field_to_search3 = "category";
To:
Code:
if(isset($_GET['category'])){
$field_to_search3 = $_GET['category'];
}else{
$field_to_search3 = What_if_category_not_searched?
}
This should work
Wistow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-03-2007, 16:52   #3 (permalink)
Newbie
 
Join Date: Mar 2007
Posts: 12
iTrader: 0 / 0%
ShaunBurden is an unknown quantity at this point
Default

Sorry, I'm not sure what you mean by putting the code in the left column, because it's already in the left column.
ShaunBurden is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-03-2007, 17:15   #4 (permalink)
Newbie
 
Join Date: Mar 2007
Posts: 12
iTrader: 0 / 0%
ShaunBurden is an unknown quantity at this point
Default

I've discovered that it only deletes things that are below the code, becasue when I look at the html, the right hand column is actually below the php code, so everything that is below the php code is deleted until the actual search is done.

I still have no idea why though.
ShaunBurden is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-03-2007, 21:04   #5 (permalink)
Moderator
 
Join Date: Mar 2005
Location: Barnsley, UK
Posts: 1,001
iTrader: 0 / 0%
Wistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond repute
Default

Check to see if you are missing a } at the end of the php code
Wistow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-03-2007, 15:17   #6 (permalink)
Newbie
 
Join Date: Mar 2007
Posts: 12
iTrader: 0 / 0%
ShaunBurden is an unknown quantity at this point
Default

Here's the link to the page. I've tried everything I know but it still won't do what I need it to do.

http://www.pwamm.com/articlelinks.php

You'll see that when the page comes in it doesn't show the right side column or the bottom bar, but when a search is made and results are shown then it brings them back in.

Maybe seeing it will help understand it.
ShaunBurden is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-03-2007, 17:36   #7 (permalink)
Super Moderator
 
Join Date: Mar 2005
Location: Herts, UK
Posts: 1,030
iTrader: 1 / 100%
monaghan is a jewel in the rough
Default

Looking at the page code, you don't have anythign past the "Please enter a search..."

Check your error log as there's probably a PHP error which causes the page generation to terminate prior to sendign everything.
monaghan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-03-2007, 15:01   #8 (permalink)
Newbie
 
Join Date: Mar 2007
Posts: 12
iTrader: 0 / 0%
ShaunBurden is an unknown quantity at this point
Default A problem with exit () and my search engine!

Hi, I've discovered why it isn't working, so I just need some help with solving the problem. The problem is that the everything after the php code is deleted, or so I thought.

Turns out that it's because of an exit command, which causes the rest of the page to stop and so doesn't get displayed. Here's the code :

PHP Code:
<?
if ($trimmed == "")
{
echo 
"<p>Please enter a search...</p>";
exit;
}

$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);

if (
$numrows == 0)
{
echo 
"<h4>Articles</h4>";
echo 
"<p>Sorry, your search: " $trimmed " returned zero results</p>";
}
if (empty(
$s))
{
$s=0;
}

$result mysql_query($query) or die("Couldn't execute query");
if(
$numrows 1){ $return "results";}
else{ 
$return "result"; }

$count $s;

while (
$rmysql_fetch_assoc($result))
{
$id $r["id"];
$header $r["header"];
$image $r["image"];
$excerpt $r["excerpt"];

$count++;
?>

       <a href="http://www.pwamm.com/articles.php?id=<? echo $id ?>"><br />
       <? echo $header ?></a><br />
       <? echo $excerpt ?><br />

<? ?>
As you can see there is an exit command at the top. I've tried taking this out, but that cause all the contents of the database to be displayed, thinking that a search has been made when the page is first loaded.

So, I need to know how I can change the code in such a way that the rest of the script is loaded, by taking the exit out, and that the database contents are shown only when a search has been made!

Cheers!
ShaunBurden is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-03-2007, 16:35   #9 (permalink)
Moderator
 
Join Date: Mar 2005
Location: Barnsley, UK
Posts: 1,001
iTrader: 0 / 0%
Wistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond repute
Default

Change
Code:
if ($trimmed == "")
{
echo "<p>Please enter a search...</p>";
exit;
}
to
Code:
if(empty($trimmed))
{
echo "<p>Please enter a search...</p>";
exit;
}
Wistow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-03-2007, 16:38   #10 (permalink)
Moderator
 
Join Date: Mar 2005
Location: Barnsley, UK
Posts: 1,001
iTrader: 0 / 0%
Wistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond reputeWistow has a reputation beyond repute
Default

If that doesn't work lookup switch statements on google
Wistow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
engine, problem, search

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
A new search engine that I built farmer_Tom Online Marketing and Website Promotion 17 12-03-2006 16:07
Search Engine Optimization Wistow SEO Articles 2 10-10-2005 07:14
IFoundIt.net - PR3 Search Engine Wistow Websites For Sale 0 21-07-2005 17:40
Search Engine Submitter KF1 Php and MySQL 14 19-07-2005 19:22
Would you use a new search engine? Wistow General Webmaster Discussion 9 03-04-2005 19:53


All times are GMT +1. The time now is 17:59.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
UK Webmaster Forum © WebmasterTalk.co.uk | Design by Forbairt

Ad Management by RedTyger

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41