| | |
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.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
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.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
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.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
![]() |
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")
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary broken cakephp checkbox class cms code codingproblem combobox cron curl database date display domain dynamic echo email error file files folder form format forms function functions google href htaccess html image include insert interactive ip java javascript joomla js limit link load login mail malfunctioning menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion reference remote return script search server sessions sms source space sql syntax system table tutorial unset up-to-date update upload url validation validator variable video web webapplications websitecontactform youtube





Im really lost... 
