簡體   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