tags:

views:

14

answers:

1

Hello!

I have this database table:

id  | url
-----------------------------------------
1   | http://stackoverflow.com/
2   | http://www.google.com
3   | http://example.com/somepage
4   | https://another.net?id=88
5   | http://hello.org/index.php?hello=2
6   | http://google.com?q=hello+world

I need to search all fields, where URL belongs to a certain host.

For example, if I give the query 'google.com', it will return rows 2 and 6 (www is ignored). I get the host using PHP parse_url() function.

How this SQL query would look like?

+3  A: 

SELECT * FROM table_name WHERE url like '%host_name%'

Replace table_name with the name of your table and replace host_name with the name of the host you are looking for to be contained in the url.

Cristian Boariu
Silver Light
Extract the query parameters from the URL and replace them in the sql i've shown you above ;)
Cristian Boariu
Silver Light
Then you should retain only the host in that table. if you retain www.google.com once the result would be correct. If this does not satisfies your needs you should redesign the table. I do not know anymore details about the application at this moment:)
Cristian Boariu
Ok, I get the idea, thank you for your help.
Silver Light