【发布时间】:2018-02-06 10:04:06
【问题描述】:
我试图弄清楚如何根据产品 ID 显示尺寸的下拉列表。我有一个包含信息的产品 tbl 和一个 productdetails tbl,它有一个 productid 作为外键、库存的尺寸和单位。
我只想显示每个特定产品可用的尺寸。
产品展示代码
<?php while ($row = $stmt-> fetch()) { ?>
<div class="col-sm-12 col-md-6">
<div class="thumbnail">
<div class="productimage">
<img src="<?= $row['pimage'] ?>" alt="<?= $row['name'] ?>" onclick="window.location.href = '../Controller/Expand.php?id=<?= $row['productid'] ?>'">
</div>
<div class="caption">
<h5><?= $row['name'] ?></h5>
<h6> <select name="size" id="size">
<?php foreach ($data as $row): ?>
<option><?= $row['size'] ?></option>
<?php endforeach ?>
</select></h6>
<br/>
</div>
</div>
</div>
<?php
}
?>
展示店
<?php
require_once 'DatabaseConnection.php';
extract($_GET);
$sql = "SELECT
Product.name,
Product.colour,
Product.unitprice,
Product.pimage,
Product.unitweight,
ProductDetails.unitsinstock,
ProductDetails.size,
Product.discount,
Product.productid,
ProductDetails.productid
FROM
Product,
ProductDetails
WHERE
Product.productid=ProductDetails.productid
AND
ProductDetails.unitsinstock>0";
$stmt = $pdo->prepare($sql) or die(implode(':', $stmt->errorInfo()));
$stmt->execute() or die(implode(':', $stmt->errorInfo()));
$cols = $stmt->columnCount();
Sizes.Controller
<?php
require_once 'DatabaseConnection.php';
$smt = $pdo->prepare("SELECT ProductDetails.size, ProductDetails.productid, Product.productid
FROM ProductDetails, Product
WHERE unitsinstock>0
AND ProductDetails.productid=Product.productid");
$smt->execute();
$data = $smt->fetchAll();
任何帮助将不胜感激!谢谢
【问题讨论】:
-
你在
product display code有什么问题? -
它在下面打印的 Display Shop 代码中运行查询。
-
尝试将
$row = $stmt->fetch()更改为$row = $stmt->fetch(PDO::FETCH_ASSOC) -
尝试了 (PDO::FETCH_ASSOC) 但我仍然有相同的输出。 :(
标签: php database phpmyadmin