简体   繁体   English

如何从两个不相关的表中选择

[英]How to select from two unrelated tables

Hey I have a query where i want to get one row from two tables they are not joined as theres no logic for them to be, but i wish to collected the info from both tables in a single query if that is at all possible??? 嘿,我有一个查询,我想从两个表中获取一行而不将它们联接在一起,因为没有逻辑,但是如果可能的话,我希望在一个查询中从两个表中收集信息? ?

This is my current prepared statement: 这是我当前准备的声明:

SELECT 
   t1.id AS tid, item_name,price,user_name
FROM 
   users t1, items t2
WHERE
    t1.uid=$uid AND t2.id=$item_id AND t2.price <= t1.users_deposit

I made a quick pastie for the code: http://www.paste.to/MjU3NDE= 我对代码进行了快速粘贴: http : //www.paste.to/MjU3NDE=

Currently when i try it and i echo $row['tid']; 目前,当我尝试并echo $row['tid']; further into my script i get no output but I equally don't get undefined error. 在我的脚本中,我没有输出任何信息,但同样也没有得到未定义的错误。 So im thinking the way i select two rows is the problem. 所以我想我选择两行的方式是问题。

您永远不会定义$row

while ($row = $stmt->fetch()) {

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

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