我创建了图书网站,我的表格如下:
现在我想,如果有人打开,作者假设(艾哈迈德·拉扎),所以我想展示作者的书,如果是他写的书,甚至是他编的书。
编译后的书籍和作者id被输入到authors_compile_rel表中。
我创建了下面的查询,但它没有显示作者编译的书籍。
$auth_id = mysql_real_escape_string($_GET['id']);
$query = "
SELECT b.id, b.unique_name, b.native_name, b.auth_id, b.status, b.create_date, ar.auth_id FROM books b, authors_compile_rel ar
WHERE b.status = 1 AND b.auth_id = ".$auth_id." OR b.t_auth_id = ".$auth_id."
OR b.id = ".$auth_id." OR ar.auth_id = ".$auth_id."
ORDER by id DESC";发布于 2015-06-26 01:19:42
书籍和authors_compile_rel表之间一定有关系,也许是book_id。我假设有这个字段作为外键:
SELECT
b.id, b.unique_name, b.native_name, b.auth_id, b.status, b.create_date, ar.auth_id
FROM books b LEFT OUTER JOIN authors_compile_rel ar ON (b.id = ar.book_id)
WHERE
b.status = 1 AND ( b.auth_id = ".$auth_id." OR b.t_auth_id = ".$auth_id." OR ar.auth_id = ".$auth_id." )
ORDER by b.id DESChttps://stackoverflow.com/questions/31062744
复制相似问题