0

现在我需要展示产品的图片,它以 id 号命名。不像这样工作:

 $cat_list .= "Product ID: $id - <strong>$product_name</strong> - <img src=inventory_images/'$id'.jpg"> <br />";

我该怎么做!??!它不是那样工作的,整个代码是这样的:

<?php 
$cat_list="";
$cat=$_GET['cat'];
$cat_sql="SELECT * FROM products,prod_cat,categories WHERE categories.id=prod_cat.cat_id AND products.id=prod_cat.prod_id AND categories.id=$cat";
$cat_query=mysql_query($cat_sql) or die(mysql_error());
$productCount = mysql_num_rows($cat_query); // count the output amount
if ($productCount > 0) {
    while($row = mysql_fetch_array($cat_query)){ 
             $id = $row["id"];
             $product_name = $row["product_name"];
             $cat_list .= "Product ID: $id - <strong>$product_name</strong> -&nbsp; &nbsp; &nbsp; <br />";
    }
}
?>
4

5 回答 5

0

$cat_list = "";
$cat = $_GET['cat'];
$cat_sql="SELECT * FROM products,prod_cat,categories WHERE categories.id=prod_cat.cat_id AND products.id=prod_cat.prod_id AND categories.id=$cat";

$cat_query = mysql_query($cat_sql) 或死(mysql_error());
$productCount = mysql_num_rows($cat_query); // 统计输出数量

if ($productCount > 0) {
        while($row = mysql_fetch_array($cat_query)) {
               $id = $row["id"];
               $product_name = $row["product_name"];
               $ext = "jpg" ;
               echo sprintf('产品 ID: %s - %s -      
', $id , $product_name , %id , $ext);
} }

请确保图像扩展名是 jpg,如果不是则替换 $ext 变量的值

于 2013-02-12T09:08:52.633 回答
0

$cat_list 字符串中的语法错误:

$cat_list .= "Product ID: $id - <strong>$product_name</strong> - <img src='inventory_images/$id.jpg'> <br />";
于 2013-02-12T08:44:02.753 回答
0

由于引用设置不正确,您的第一个代码段无法工作。将其更改为

$cat_list .= "Product ID: $id - <strong>$product_name</strong> - <img src='inventory_images/$id.jpg'> <br />";
于 2013-02-12T08:44:05.173 回答
0
$cat_list .= "Product ID: $id - <strong>$product_name</strong> - <img src=\"inventory_images/$id.jpg\"> <br />";

你忘了把“qoute”放在后面src=吗?

于 2013-02-12T08:44:19.943 回答
0

你没有回应任何东西。

$cat_list="";
$cat=$_GET['cat'];
$cat_sql="SELECT * FROM products,prod_cat,categories WHERE categories.id=prod_cat.cat_id AND products.id=prod_cat.prod_id AND categories.id=$cat";
$cat_query=mysql_query($cat_sql) or die(mysql_error());
$productCount = mysql_num_rows($cat_query); // count the output amount
if ($productCount > 0) {
    while($row = mysql_fetch_array($cat_query)){ 
             $id = $row["id"];
             $product_name = $row["product_name"];
             echo 'Product ID: $id - <strong>$product_name</strong> - <img src="inventory_images/'.$id.'.jpg" />&nbsp; &nbsp; &nbsp; <br />';
    }
}
于 2013-02-12T08:45:47.093 回答