dpq39825 2015-11-16 13:03
浏览 103
已采纳

如果我在数据库中有两个表,并且我想从一个表用户id获取到其他表数据,那么如何从php中的数据库中获取数据[关闭]

I have created two table name is 'orders' and 'registration' in one database. when I am registering that is working fine and when i am trying to logged in with current registration that is also working fine. but

problem is only that suppose 5 users registered there and they submitted different orders. after loggin while going to see history of orders all users are seeing the same history and all are able to see each others orders in his account after logged in . I am only trying to stop this. so that only logged users can see their own submission only. they should be able to see others user order

  • 写回答

3条回答 默认 最新

  • dongshi6710 2015-11-16 13:56
    关注

    As database schema is not available, I'm assuming the structure like this. Change it where you need.

    registration table

    Id | firstName | lastName | email | ....
    

    Where, Id is Primary Key and auto-incremented

    orders table

    orderId | userID | orderName | ...
    

    Where, orderId is Primary Key and auto-incremented ; userID is Id of registration table.

    So, when you are logged in through registration table. Create one session for Id.

    $_Session['user_id']; (Id of registration table will be stored here.)

    For viewing his/her orders

    <?
    $userID=$_SESSION['user_id'];
    $orderQuery="SELECT * FROM orders WHERE userID=$userID";
    .
    .//Execute Your query
    .
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?