views:

53

answers:

2

Ok, i'm trying to get data from a database to be pulled according to the url.

I have a database that is holding data for some announcements for individual customer websites. The websites are in individual directories on my website. (i.e., www.domain.com/website1/index.html, www.domain.com/website2/index.html, www.domain.com/website3/index.html, etc..) In the database i have a column that has each customers "filing name" (aka directory name - website1, website2, website3, etc..). I want to try and display only rows in the database where filingName = website1 for the domain "www.domain.com/website1/index.html". Hope this makes sense. I'm basically trying to figure out how to connect the dots between a single page and only pulling a specific customers records. Any thoughts??

Thanks!

A: 

Use a like statement in your query:

SELECT * FROM `sites` WHERE `url` LIKE "%/website1/%";
Cody Snider
Alternately, you could use REGEXP, but I believe that would be a more expensive query for something like this.
Cody Snider
Such queries require full table scan almost always so... That's not for using in middle-to-large projects.
FractalizeR
+1  A: 

Depending on how big your data set is, it might be "cheaper" to preprocess the URLs and store the individual components you need to match on. e.g. create extra fields for host/dir/querystring and store those individually, instead of a monolithic absolute URL. This would be safer than trying to do substring matches, especially if the substring you're matching could be part of multiple different urls ('abc' being part of 'abc.com' and 'abctv.com').

Marc B