简体   繁体   中英

php differentiate between different table id's?

i have different objects with there id's, all id's are unique.

objects

  • photo
  • feed
  • event
  • comment

all of there id's are unique and never repeated again.

i want to pass that id in url like this: http://domain.com/ {object_id} and object id should tell me, which object it belongs to and what it id is. maybe doing it through php.

i read somewhere that it can be done it through base_convert with prepending text or different id. not sure.

edited:

current ids and url

lets say we are on this page http://domain.com/654156165165 , how would we know if this is id of photo, feed, event or comment?

solution 1 i was thinking about

  • reproduce the id with prepend/append some integer, to identify which object it belongs to
  • page is requested with new id http://domain.com/654646545412
  • check with php which object this id belongs to and what was the actual id of that object (after removing prepended/appended integer)

Just query a database for the object details. I am sure you have object type stored there.

You should query the database for the object. You mention that this is prohibitive due to overhead however with proper indexing this shouldn't be to bad as long as you include the WHERE id = :objectID in your queries. Alternatively you could create an object table which has all of the ID's along with the type of object they are, query that for the object, then query only the appropriate table.

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