繁体   English   中英

通过从具有公用列的两个表中选择数据来获得未定义的索引

[英]undefined index by selecting data from two tables with a common column

我有两张桌子- homeposts ; home.artid等于posts.id

想要从posts选择id, artid, inde以及home title
其中home.posslider

$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;

错误:
未定义索引posts.title...

有什么帮助吗?

如果要选择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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM