RyanPitts
RyanPitts

Reputation: 601

PHP Parsing URL

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!

Upvotes: 0

Views: 595

Answers (3)

Isaac Dozier
Isaac Dozier

Reputation: 86

Your best bet is going to be to store these identifiers on their own in the database (ex 1= website1, 2 = website 2) and name the directories accordingly. Then in your .htaccess file, manipulate the URL to look like your $_GET variable is the directory name, replace it with the matching name in your database. Do this with RewriteRule rule. This is the most absolute way to achieve this while keeping the same URL structure.

edit: whoops, didn't realize how old this thread was.

Upvotes: 0

Marc B
Marc B

Reputation: 360922

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').

Upvotes: 1

Cody Snider
Cody Snider

Reputation: 368

Use a like statement in your query:

SELECT * FROM `sites` WHERE `url` LIKE "%/website1/%";

Upvotes: 0

Related Questions