私はPDOを使用していますが、私のクエリをtryブロックに入れて、準備してからexecuteを実行して、次にfetchAll(PDO::FETCH_ASSOC)
を呼び出します。その行の中で私はforeachループでPHPを配置したテキストが必要です。$tools
変数は$obj
です。私は私のコードに変数 '$obj
'を 'name'、 'price'、および 'code'のmySQLからの参照を入れて呼び出すと思いました。 だけ object(PDOStatement)#2(1){["queryString"]}=>...the Sql statmement.
PHP PDOクエリの問題がオブジェクト=> "queryString"として返される
try {
$tools = $dbh->prepare("SELECT t.item_code as code, t.item_name as
name, t.retail_price as retail,
t.sale_price as price, t.item_pieces as
pieces, t.qty as quantity,
t.sold as sold, b.brand as brand,
c.category as category
FROM Tools AS t
JOIN Images AS i ON t.t_id = i.t_id
JOIN Brands AS b ON t.b_id = b.b_id
JOIN Categories AS c ON t.c_id =
c.c_id
LEFT OUTER JOIN Types as tt ON tt.t_id = t.tt_id");
$tools->execute();
$tools->fetchAll(PDO::FETCH_ASSOC);
}catch (PDOException $e) {
echo 'unable to retrieve data';
echo $e->getMessage();
exit();
}
<?php
foreach($tools as $obj) {
?>
<div class="col-xs-12 col-sm-6 col-md-3">
<article class="card">
<p class="text-center">
Item: <?php echo $obj->name; ?><br>
Brand: <br>
Price: <?php echo $obj->price; ?><br>
<button class="btn btn-default btn-lg"
value="<?php echo $obj->name; ?>">
<a href="#"><?php echo $obj->code;
?></a>
</button>
</p>
</article>
</div>
<?php } ?>
Webページをwithingコードメッセージをクエリ文字列を吐き出しのエラー。
`object(PDOStatement)#2 (1) { ["queryString"]=> string(609) "SELECT t.item_code as code, t.item_name as name, t.retail_price as retail, t.sale_price as price, t.item_pieces as pieces, t.qty as quantity, t.sold as sold, b.brand as brand, c.category as category FROM Tools AS t JOIN Images AS i ON t.t_id = i.t_id JOIN Brands AS b ON t.b_id = b.b_id JOIN Categories AS c ON t.c_id = c.c_id LEFT OUTER JOIN Types as tt ON tt.t_id = t.tt_id" }`
ご協力いただきありがとうございます。 – mikeyjhavoc