Jump to content


Photo

General question


  • Please log in to reply
11 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 02 August 2006 - 03:57 PM

hi guys,
I have a very simple question:
I want to make a search engine for my site, can u tell me wich is the best way to do this? I don't know how to do that, your ideas will be very helpfull for me, thanks.
I don't need your script, I'll try to write it myself

#2 PHPSpirit

PHPSpirit
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 04:46 PM



Put all your data in a database is the better way.



#3 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 02 August 2006 - 04:59 PM

If your whole site is in a databse, like MySQL, then a search if a very easy thing to implement. If your site is in html files, you can create your own search script in php, but depending on how you do it it might be slow, and might not be the best way of doing things.

If you're looking for a super easy solution, you can use Google.. they have a feature that you can use that will allow users to search YOUR site.. you might want to check into that.

#4 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 02 August 2006 - 05:09 PM

Google, that requires the site to be in googles database.
which is quite not that easy
I am a PHP Guru, ask me questions if you want to

#5 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 02 August 2006 - 05:12 PM

Well if the site has been online for a couple of weeks, it's sure to be in google. Google is usually pretty fast at that.

#6 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 03 August 2006 - 03:04 PM

no, my sites up for months and yet its not in google database
I am a PHP Guru, ask me questions if you want to

#7 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 03 August 2006 - 03:32 PM

ok guys, here is my simple search script, but it doesn't work...
any ideas? thank you for your comments.

<?php
$con = mysql_connect("localhost","3d","password");
if(!con){
  die('Can not connect:'.mysql_error());
}
mysql_select_db("3d",$con);
$result = mysql_query("SELECT*FROM search WHERE text");
while($row = mysql_fetch_array($result))
if($result == '$_POST[search]')
  echo $row['text'];
else
  echo "sorry";
mysql_close($con);
?>

I don't need your script, I'll try to write it myself

#8 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 03 August 2006 - 03:49 PM

Regarding your query:

$result = mysql_query("SELECT*FROM search WHERE text");

What data is contained in the "search" table?

You specify "WHERE text", but you don't tell MySQL what to check "text" against. This would only work if you did something like:

$result = mysql_query("SELECT * FROM search WHERE text = '$somevar'");

What you'll need to do is something like this. Start by mapping out what tables in the database you want to search. For example, let's say your website has news articles, with the following database structure:

news_table
news_id
news_title
news_text

You would want to structure your query simiarl to this:

$sql = "SELECT * FROM news_table 
          WHERE news_title LIKE '%".$_POST['search']."%'
          OR news_text LIKE '%".$_POST['search']."%'";
$result = mysql_query($sql);

You would need to perform a "LIKE" statement for each field in the database you want to check.

#9 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 03 August 2006 - 03:53 PM

ok, but how can Compare that to the inputed text from the form?
I don't need your script, I'll try to write it myself

#10 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 03 August 2006 - 04:04 PM

The query I wrote already compares the database to the search text (
$_POST['search']
), and it only returns the matches.

There's no need to do any other comparison, all you have to do from that point is print out the results.

#11 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 04 August 2006 - 08:22 AM

ok, thanks I've done it but when I try to print the result it says: Resource id #3 - what does that mean?
here is the code:

$sql = "SELECT * FROM search
          WHERE text LIKE '%".$_POST['search']."%'
          OR news_text LIKE '%".$_POST['search']."%'";
$result = mysql_query($sql);
echo $result;
mysql_close($con);

I don't need your script, I'll try to write it myself

#12 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 August 2006 - 10:30 AM

but when I try to print the result it says: Resource id #3 - what does that mean?

It means you should read the manual to find out what the mysql_query() function returns.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users