Gruzin Posted August 2, 2006 Share Posted August 2, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16341-general-question/ Share on other sites More sharing options...
PHPSpirit Posted August 2, 2006 Share Posted August 2, 2006 Put all your data in a database is the better way. Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-67920 Share on other sites More sharing options...
bpops Posted August 2, 2006 Share Posted August 2, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-67932 Share on other sites More sharing options...
Chetan Posted August 2, 2006 Share Posted August 2, 2006 Google, that requires the site to be in googles database.which is quite not that easy Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-67942 Share on other sites More sharing options...
bpops Posted August 2, 2006 Share Posted August 2, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-67945 Share on other sites More sharing options...
Chetan Posted August 3, 2006 Share Posted August 3, 2006 no, my sites up for months and yet its not in google database Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-68586 Share on other sites More sharing options...
Gruzin Posted August 3, 2006 Author Share Posted August 3, 2006 ok guys, here is my simple search script, but it doesn't work...any ideas? thank you for your comments.[color=red]<?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);?>[/color] Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-68602 Share on other sites More sharing options...
HeyRay2 Posted August 3, 2006 Share Posted August 3, 2006 Regarding your query:[code=php:0]$result = mysql_query("SELECT*FROM search WHERE text");[/code]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:[code=php:0]$result = mysql_query("SELECT * FROM search WHERE text = '$somevar'");[/code]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:[b]news_table[/b]news_idnews_titlenews_textYou would want to structure your query simiarl to this:[code=php:0]$sql = "SELECT * FROM news_table WHERE news_title LIKE '%".$_POST['search']."%' OR news_text LIKE '%".$_POST['search']."%'";$result = mysql_query($sql);[/code]You would need to perform a "LIKE" statement for each field in the database you want to check. Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-68616 Share on other sites More sharing options...
Gruzin Posted August 3, 2006 Author Share Posted August 3, 2006 ok, but how can Compare that to the inputed text from the form? Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-68623 Share on other sites More sharing options...
HeyRay2 Posted August 3, 2006 Share Posted August 3, 2006 The query I wrote already compares the database to the search text ([code=php:0]$_POST['search'][/code]), 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. Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-68631 Share on other sites More sharing options...
Gruzin Posted August 4, 2006 Author Share Posted August 4, 2006 ok, thanks I've done it but when I try to print the result it says: [color=green]Resource id #3[/color] - what does that mean?here is the code:[color=red]$sql = "SELECT * FROM search WHERE text LIKE '%".$_POST['search']."%' OR news_text LIKE '%".$_POST['search']."%'";$result = mysql_query($sql);echo $result;mysql_close($con);[/color] Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-69036 Share on other sites More sharing options...
trq Posted August 4, 2006 Share Posted August 4, 2006 [quote]but when I try to print the result it says: Resource id #3 - what does that mean?[/quote]It means you should read the manual to find out what the [url=http://php.net/mysql_query]mysql_query[/url]() function returns. Link to comment https://forums.phpfreaks.com/topic/16341-general-question/#findComment-69062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.