[英]PHP/MySQL join 2 tables
我有一个带有用户名,密码和属性名的mysql表,允许用户登录到安全站点部分。 现在我想要做的是从第二个表中插入pdf,它从表一中检查表一中的属性名称,对照表二中pdfs的documentCategory,然后根据记录显示相关的pdf - 用户。 (希望这是有道理的)
表结构:
Table 1 -
userid password property
Table 2 -
pdfFile documentCategory
Where table1.property = table2.documentCategory
任何帮助我如何在PHP中工作将非常感激,因为我现在完全失去了。
小号
如果用户已经登录(即,您具有userid
),则SQL查询可能如下所示:
$query = 'SELECT pdfFile
FROM table2
INNER JOIN table1 ON property = documentCategory
WHERE table1.userid = '.intval($userid);
$result = mysql_query($query);
将其与您首选的数据库抽象层相匹配。
SELECT table2.pdfFile,table2.documentCategory FROM table2,table1 WHERE table1.property = table2.documentCategory AND table1.user_id =?
确保table1.user_id具有PRIMARY索引,table2.documentCategory也具有索引。
select t2.pdfFile
from t1 inner join t2
on t1.property = t2.documentCategory
where t1.userId = $userId
更新...不确定这是一个php问题......更像是一个SQL问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.