如何在 zend 框架中使用 join 查询获取选定的用户详细信息
嗨,我是 zend 和 mysql 的新手,所以如果这是一个愚蠢的问题,请忽略。我有两个表:users 和 user_cars。现在 user_cars 表包含拥有多辆汽车的同一用户。即,如果用户拥有三辆不同的汽车,则 user_cars 表包含该用户的三个条目。现在我想从 user_cars 表中选择一个特定用户。 userid 是给我的。谁能告诉我该怎么做。
users:
userid, username, password, fname, lname // columns
user_cars:
id, userid, car_name, purchase_date // columns
所以我有一个用户 ID,并希望从 user_cars 中选择具有给定用户 ID 的所有行。谁能告诉我该怎么做。
Hi i am new to zend and mysql so please ignore if this is a silly ques. i have two tabels: users and user_cars. Now the user_cars table contains same user with multiple cars. i.e. if a user has three different cars, then the user_cars table contains three entries for that user. Now i want to select a particular user from user_cars table. The userid is given to me. can anyone please tell me how to do that.
users:
userid, username, password, fname, lname // columns
user_cars:
id, userid, car_name, purchase_date // columns
so i have a userid and want to select all the rows from user_cars with the given userid. can anyone please tell me how to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
但你问的实在不清楚,所以也许不是这个
But what you're asking is really not clear so maybe it's not this
选择a.userid、a.username、a.fname、a.lname、b.car_name、b.purchase_date
来自用户 a、user_cars b
其中 a.userid = b.userit 和 a.userid = 1
这会选择 userid 1 的用户名、名字和姓氏、汽车名称和购买日期
select a.userid, a.username, a.fname, a.lname, b.car_name, b.purchase_date
from users a, user_cars b
where a.userid = b.userit and a.userid = 1
this selects username, first and last name, and car name and purchase date for userid 1