gpt4 book ai didi

php - php mysql 如何从博客中选择作者、帖子和浏览量三张表并显示?

转载 作者:行者123 更新时间:2023-11-30 21:47:51 25 4
gpt4 key购买 nike

我尝试为第三个选择连接的表是 viewcount,它通过 prints.print_id = totalview.name 连接到“prints”表

因此此处的选择有效但添加第三个表无效。我的查询有什么问题?成功了!

$q = "SELECT artists.artist_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name, price, description, print_id, image_name FROM artists, prints WHERE artists.artist_id = prints.artist_id ORDER BY artists.last_name ASC, prints.print_id ASC";

错误!

$q = "SELECT artists.artist_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name, price, description, print_id, image_name, totalview.totalvisit AS totalvisit FROM artists, prints WHERE artists.artist_id = prints.artist_id, LEFT JOIN totalview ON totalview.print = prints.print_id ORDER BY artists.last_name ASC, prints.print_id ASC";

enter image description here enter image description here

enter image description here

在表格中显示:

$r = mysqli_query ($dbc, $q);
while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {

// Display each record:
echo "\t<tr>
<td align=\"left\"><a href=\"browse_prints.php?aid={$row['artist_id']}\">{$row['artist']}</a></td>
<td align=\"left\"><a href=\"view_print.php?pid={$row['print_id']}&name={$row['image_name']}\">{$row['print_name']}</a></td>
<td align=\"left\">{$row['description']}</td>
<td align=\"left\">{$row['description']}</td>
<td align=\"right\">\${$row['price']}</td>
</tr>\n";

最佳答案

左连接子句在错误的位置..你不能在 where 之后添加左连接子句

并且不要混淆明确和隐式连接使用显式最后(希望)你在 where 条件之后也有一个错误的逗号

$q = "SELECT 
artists.artist_id
, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist
, print_name
, price
, description
, print_id
, image_name
, totalview.totalvisit AS totalvisit
FROM artists
INNER JOIN prints ON rtists.artist_id = prints.artist_id
LEFT JOIN totalview ON totalview.print = prints.print_id
ORDER BY artists.last_name ASC, prints.print_id ASC";

关于php - php mysql 如何从博客中选择作者、帖子和浏览量三张表并显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48601828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com