简体   繁体   中英

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. (ie, 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!

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

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.

在查询中使用like语句:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM