在我的代码中,我想使用标题属性,正如您在我的代码中看到的那样 title="'. $title .'"
。目前 $title 不返回任何内容,但它应该从数据库返回一个值。标题值存储到另一个 MySQL 表 (product_titles) 中。
我的目标是从表“产品”中获取“名称”列的字段值。如果该字段的值与 utf8_encode($row_Bereich2->name)
相同,那么它应该返回“product_title”列的字段值。
if(!$result = $db->query("SELECT name FROM produkteguide_kategorien_alle_bereiche WHERE bereich = 2")){
die('Error');
}
while($row_Bereich2 = $result->fetch_object()){
$Select_Bereich2 .= '<input type="checkbox" id="'. utf8_encode($row_Bereich2->name) .'"><label for="'. utf8_encode($row_Bereich2->name) .'">'. utf8_encode($row_Bereich2->name) .'</label> <div title="'. $title .'" class="info_box">i</div><br>';
}
我该怎么做?
最佳答案
LEFT JOIN这就是您正在寻找的。p>
SELECT kat.name, prod.product_title
FROM produkteguide_kategorien_alle_bereiche kat
LEFT JOIN products prod ON (kat.name = prod.name)
WHERE ...
关于php - 从第二个 MySQL 表获取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33394755/