| | |
MySQL Search - Google like?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Ive got a MySQL search, which searches an index of urls. The search parameter searches titles. What I want to do is have something like Google.
So, if someone searches:
It would look for example.com in one column then from those results it would look for 'something to search' in another given column.
How would I do this?
So, if someone searches:
PHP Syntax (Toggle Plain Text)
site:example.com something to search
It would look for example.com in one column then from those results it would look for 'something to search' in another given column.
How would I do this?
So would I do something like
Is that right? Just guess work :p
mysql Syntax (Toggle Plain Text)
SELECT FROM table1 WHERE column1='$foo' IN table1 WHERE column1='$foo2'
Is that right? Just guess work :p
•
•
•
•
So would I do something like
mysql Syntax (Toggle Plain Text)
SELECT FROM table1 WHERE column1='$foo' IN table1 WHERE column1='$foo2'
Is that right? Just guess work :p
site: within a string use the following: php Syntax (Toggle Plain Text)
$string='test site:example.com site:test.com test2'; if (preg_match('/site:/i',$string)) { preg_match_all('/site:[^ ]+/i',$string,$site); for ($ii=0;isset($site[0][$ii]);$ii++) { $site[0][$ii]=strtolower(substr($site[0][$ii],5,strlen($site[0][$ii]))); } $sites=$site[0]; unset($site); //now to display it foreach ($sites AS $siteval) { echo $siteval."<br>"; } }
php Syntax (Toggle Plain Text)
mysql_query("SELECT * FROM `table` WHERE `domain`='".mysql_real_escape_string($sites[0])."'");
Last edited by cwarn23; Feb 27th, 2009 at 2:10 am.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
Thats amazing, thank you so much. What I will have to do is to tell my users to set site:example.com first then put the query. To make it easier.
So, to get the query. Ive done this...
It works but is pretty rudimentary, would you recomend something better?
EDIT: This is my final code. Im really tired now and there are probably loads of errors lol.
So, to get the query. Ive done this...
php Syntax (Toggle Plain Text)
$search = explode(' ', $string); echo $search[1];
It works but is pretty rudimentary, would you recomend something better?
EDIT: This is my final code. Im really tired now and there are probably loads of errors lol.
php Syntax (Toggle Plain Text)
$search= $_GET['q']; if (preg_match('/site:/i',$string)) { preg_match_all('/site:[^ ]+/i',$string,$site); for ($ii=0;isset($site[0][$ii]);$ii++) { $site[0][$ii]=strtolower(substr($site[0][$ii],5,strlen($site[0][$ii]))); } $sites=$site[0]; $query = explode(' ', $string); $sql = "SELECT * FROM list WHERE title LIKE '%$query%' AND WHERE url LIKE '%$sites%'"; } else { $sql = "SELECT * FROM list WHERE title LIKE '%$search%'"; }
Last edited by !Unreal; Feb 27th, 2009 at 5:53 am.
•
•
•
•
Thats amazing, thank you so much. What I will have to do is to tell my users to set site:example.com first then put the query. To make it easier.
So, to get the query. Ive done this...
php Syntax (Toggle Plain Text)
$search = explode(' ', $string); echo $search[1];
It works but is pretty rudimentary, would you recomend something better?
php Syntax (Toggle Plain Text)
$string='test site:example.com site:test.com test2'; if (preg_match('/site:/i',$string)) { preg_match_all('/site:[^ ]+/i',$string,$site); for ($ii=0;isset($site[0][$ii]);$ii++) { $site[0][$ii]=strtolower(substr($site[0][$ii],5,strlen($site[0][$ii]))); } $sites=$site[0]; unset($site); } $search=explode(' ',preg_replace('/[\h]+/',' ',preg_replace('/site:[^\h]+/i','',$string))); //now to display echo "<b>Sites</b><br>"; foreach ($sites AS $siteval) { echo $siteval."<br>"; } echo "<br><b>Keywords</b>"; foreach ($search AS $val) { echo "<br>".$val; }
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
Hmm...doesnt seem to be working. Is this query valid?
mysql Syntax (Toggle Plain Text)
SELECT * FROM list WHERE title LIKE '%$search%' AND WHERE url LIKE '%$sites%'
•
•
•
•
Hmm...doesnt seem to be working. Is this query valid?
mysql Syntax (Toggle Plain Text)
SELECT * FROM list WHERE title LIKE '%$search%' AND WHERE url LIKE '%$sites%'
mysql Syntax (Toggle Plain Text)
SELECT * FROM list WHERE title LIKE '%$search%' AND url LIKE '%$sites%'
php Syntax (Toggle Plain Text)
mysql_query("SELECT * FROM `list` WHERE `title` LIKE '%".$search."%' AND `url` LIKE '%".$sites."%'");
php Syntax (Toggle Plain Text)
mysql_query("SELECT * FROM `list` WHERE `title` LIKE '%".$search[0]."%' AND `url` LIKE '%".$sites[0]."%'");
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
![]() |
Similar Threads
- how to import excel data into mySql (PHP)
- Inserting into Table (MySql) (JSP)
- In Mysql Storing and retriving the image with asp.net (MySQL)
- Problems connecting jsp with MySQL database (JSP)
- How to install MySql++ in redhat enterprise 5 (C++)
- multiple search terms+fulltext search (MySQL)
- mysql search and display data help.... (MySQL)
- how deposit a picture to MYSQL database (PHP)
- pagination of mysql query results (PHP)
- Hi I've been told by my bf that php and mysql are very very powerful tools in the com (PHP)
Other Threads in the PHP Forum
- Previous Thread: maintaing tabbed panel focus on submit
- Next Thread: header ("POST")
Views: 1130 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cookies cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery js limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube





Im really lost... 
