是否可以在记录中存储指向另一条记录的“链接”?例如:
table USERS
id name link
-------------------------------------------------------
1 user1 [link to record with id=4 in table info]
所以,在 PHP 中,我可以这样做:
// connect to the database etc....
$query = "select * from users where id=1";
$result = mysql_query($query);
$another_result = mysql_result($result, 0, 'link');
因此 $another_result
以与使用 mysql_query()
调用时相同的原始格式存储另一个查询的结果。
这可能吗?
最佳答案
$query = "select info.* from info
inner join users on users.link = info.id
where users.id=1";
$result = mysql_query($query);
使用 JOIN
是 SQL 的基本组成部分,就像在 PHP 中使用 for
循环一样。
阅读A Visual Explanation of SQL Joins由无畏的领导者。
关于php - 类似于 MySQL 中的符号链接(symbolic link)的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8621285/