[英]undefined index by selecting data from two tables with a common column
I have two tables - home
and posts
; 我有两张桌子- home
和posts
; home.artid
is equal to posts.id
. home.artid
等于posts.id
。
Want select id, artid, inde
from home
PLUS title
from posts
想要从posts
选择id, artid, inde
以及home
title
where home.pos
is slider
: 其中home.pos
是slider
:
$items = "";
$st = $db->query("select home.id, home.artid, home.inde
from home
join posts on home.artid = posts.id
where home.pos = 'slider'
order by home.inde asc");
while ($row = $st->fetch()){
$items .= "<div class='slidertitle'>" . $row['posts.title'] . "</div>\n";
}
echo $items;
Error: 错误:
Undefined index posts.title...
未定义索引posts.title...
Any help? 有什么帮助吗?
If you want to select posts.title
then select it 如果要选择posts.title
选择它
$st = $db->query("select home.id, home.artid, home.inde,
posts.title
from home
join posts on home.artid = posts.id
where home.pos = 'slider'
order by home.inde asc");
// and it would be called just `title`
while ($row = $st->fetch()){
$items .= "<div class='slidertitle'>" . $row['title'] . "</div>\n";
}
echo $items;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.