[英]How do you pull a data from a second table that has the same id using PDO/php?
DESCRIPTION 描述
I use the script below to displays all rows in my floradstable. 我使用下面的脚本显示我的floradstable中的所有行。 I have a second table florinvtable that has identical columns.
我有第二个表florinvtable具有相同的列。 The Price column in floradstable = 0.00 whereas the Price column in florinvtable contains the real price.
floradstable中的Price列为0.00,而florinvtable中的Price列包含实际价格。
$result = $pdo->prepare(
"SELECT floradstable.Brand, florinvtable.Price
FROM floradstable INNER JOIN florinvtable
ON floradstable.Barcode=florinvtable.Barcode
ORDER BY Brand");
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC))
{
echo $row['Brand']." ";
echo $row['florinvtable.Price']." ";
echo "<a href='submit-ads-florida.php?deleteid=".$row['Barcode']."'>DELETE</a><br>";
}
OBJECTIVE 目的
I would like to echo the price from florinvtable using the unique id(Barcode) both tables share. 我想用florinvtable回复价格,使用两个表共享的唯一ID(条形码)。
PROBLEM 问题
florinvtable.Price does not echo which leads me to believe it is echo(ing) from floradstable verses florinvtable. florinvtable.Price没有回应,这让我相信它是来自floradstable诗歌florinvtable的回声。
NOTE 注意
The current script works as is, without an error but does not pull Price FROM florinvtable 当前脚本按原样运行,没有错误,但没有拉出Price FROM florinvtable
With the select you defined: 使用您定义的选择:
$result = $pdo->prepare(
"SELECT floradstable.Brand, florinvtable.Price
FROM floradstable INNER JOIN florinvtable
ON floradstable.Barcode=florinvtable.Barcode
ORDER BY Brand");
the columns in the result set are just called Brand
and Price
. 结果集中的列只称为
Brand
和Price
。 The table reference is to fetch the correct one, not part of the name. 表引用是获取正确的,而不是名称的一部分。
Try 尝试
echo $row['Price']." ";
Edit: I see you also use $row['Barcode']
, which would not be defined by that query! 编辑:我看到你也使用
$row['Barcode']
,该查询不会定义! You would need 你需要
$result = $pdo->prepare(
"SELECT floradstable.Brand, florinvtable.Price, floradstable.Barcode
FROM floradstable INNER JOIN florinvtable
ON floradstable.Barcode=florinvtable.Barcode
ORDER BY Brand");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.