[英]How do I select three tables from a blog including author, post and views and show in php mysql?
The table I am trying to connect for the third selection is the viewcount which is connected to the 'prints' table by prints.print_id = totalview.name 我要为第三个选择连接的表是viewcount,它通过prints.print_id = totalview.name连接到“ prints”表
So the selection here works but adding the third table doesn't work. 因此,此处的选择有效,但添加第三个表无效。 What is wrong with my query?
我的查询出了什么问题? WORKS!
作品!
$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";
ERROR! 错误!
$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";
To show in a table as such: 显示在表格中:
$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";
The left join clause in the wrong position .. you can't add the left join clause after the where 左连接子句位置错误..您不能在其中添加左连接子句
and don't mixup esplicit and implicit join use ever explicit and last (hope) you have also a wrong comma after the where condition 并且不要混淆显式和隐式连接使用显式和最后(希望),在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";
Your SQL is structured incorrectly: 您的SQL结构不正确:
FROM artists, prints
WHERE artists.artist_id = prints.artist_id,
LEFT JOIN totalview ON
should be 应该
FROM artists, prints
LEFT JOIN totalview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.