作者:迷失港湾的豪 | 来源:互联网 | 2023-05-18 19:25
I have a table with 4 values, 3 of which I am interested in. The MYSQL query I am using is:
我有一个包含4个值的表,其中3个我感兴趣。我使用的MYSQL查询是:
Select Product.product_id, Product.cost, Product.image from Product
I have tested this query and it works with my database. I can figure out how to get single columns to return values, but I cannot figure out multiple columns. I have tried a variety of for loops, using an array to store the various column names and iterating things. I'm getting very frustrated, and am not sure what to do.
我已经测试了这个查询,它与我的数据库一起工作。我可以算出如何让单个列返回值,但是我不能算出多个列。我尝试了各种for循环,使用一个数组来存储不同的列名称和迭代的东西。我很沮丧,不知道该怎么办。
This was my last attempt:
这是我最后一次尝试:
$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 = "";
while ( $row = $result->fetch_assoc() ){
foreach ($row as $next){
$tablebuild .= "";
$tablebuild .= $result['product_id'];
$tablebuild .= " | ";
$tablebuild .= $result['cost'];
$tablebuild .= " | ";
$tablebuild .= $result['image'];
$tablebuild .= " |
";
}
$tablebuild .= "
";
Obviously I'm trying to build it into a string of code so I can echo it later into the page where I need it. Every time I run this page, though, I get nothing but a blank page with no source code.
显然,我试图将它构建为一串代码,以便稍后在需要它的页面中进行回显。但是每次我运行这个页面时,我得到的都是一个没有源代码的空白页面。
2 个解决方案