简体   繁体   English

PHP区分不同的表ID的?

[英]php differentiate between different table id's?

i have different objects with there id's, all id's are unique. 我有具有ID的不同对象,所有ID都是唯一的。

objects 对象

  • photo 照片
  • feed 饲料
  • event 事件
  • comment 评论

all of there id's are unique and never repeated again. 所有这些ID都是唯一的,不再重复。

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. 我想像这样在URL中传递该ID: http : //domain.com/ {object_id}和对象ID应该告诉我,它属于哪个对象以及它的ID是什么。 maybe doing it through php. 也许通过PHP做到这一点。

i read somewhere that it can be done it through base_convert with prepending text or different id. 我读到某处可以通过base_convert使用前置文字或其他ID来完成。 not sure. 不确定。

edited: 编辑:

current ids and url 当前的ID和网址

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? 假设我们在此页面上http://domain.com/654156165165 ,我们怎么知道这是照片,提要,事件还是评论的ID?

solution 1 i was thinking about 解决方案1我在想

  • reproduce the id with prepend/append some integer, to identify which object it belongs to 使用前缀/附加一些整数来重现id,以标识它属于哪个对象
  • page is requested with new id http://domain.com/654646545412 请求页面使用新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) 用php检查此ID属于哪个对象以及该对象的实际ID是什么(在除去前缀/附加整数之后)

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. 您提到由于开销,这是禁止的,但是只要索引正确,只要您在查询中包含WHERE id = :objectIDWHERE id = :objectID不会很糟糕。 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. 或者,您可以创建一个对象表,其中包含所有ID以及它们的对象类型,查询该对象,然后仅查询适当的表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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