4 つの値を持つテーブルがあり、そのうち 3 つに興味があります。使用している MYSQL クエリは次のとおりです。
Select Product.product_id, Product.cost, Product.image from Product
このクエリをテストしたところ、データベースで動作します。単一の列を取得して値を返す方法は理解できますが、複数の列を理解することはできません。配列を使用してさまざまな列名を格納し、物事を反復して、さまざまな for ループを試しました。私は非常にイライラしており、どうすればよいかわかりません。
これが私の最後の試みでした:
$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or
die('There was a problem connecting to the database');
$stmt = "Select Product.product_id, Product.cost, Product.image from Product";
if(!$result = $conn->query($stmt)){
die('there was an error retrieving the information');
}
$tablebuild = "<table>";
while ( $row = $result->fetch_assoc() ){
foreach ($row as $next){
$tablebuild .= "<tr><td>";
$tablebuild .= $result['product_id'];
$tablebuild .= "</td><td>";
$tablebuild .= $result['cost'];
$tablebuild .= "</td><td>";
$tablebuild .= $result['image'];
$tablebuild .= "</td></tr>";
}
$tablebuild .= "</table>";
明らかに、私はそれをコードの文字列に構築しようとしているので、後で必要なページにエコーすることができます。ただし、このページを実行するたびに、ソース コードのない空白のページしか表示されません。