我有以下代码来显示mysql数据库中的六个产品块。 它显示为两列三行,我在六个位置中的每一个都获得单独的照片和正确的页面链接,但第一列中的三个产品的alt标签在第2列中重复。我无法弄清楚原因。有什么想法,以及改进代码的方法吗?
<?php
// create query
$query = "SELECT * FROM photogear WHERE qty != 0 ORDER BY id DESC LIMIT 6";
// execute query
$result = mysql_query($query) or die(MYSQL_ERROR);
?>
<table>
<?php
while($row = mysql_fetch_array($result)){
$product2=$row['product'];
$img2=$row['img'];
$manuid2=$row['manuid'];
$id2=$row['id'];
$price=$row['price'];
//GET MANUFACTURER FOR DISPLAY IN img title
$manu_q = "SELECT * FROM manufacturers WHERE manuid = '$manuid2' ORDER BY name";
$manu_r = mysql_query($manu_q) or die(mysql_error());
$manu_info = mysql_fetch_array($manu_r);
$name2=$manu_info['name'];
?>
<tr>
<td>
<?php // for each product show photo with a link to product page
echo "<a href='product-".$row['id']."'><img src='".$row['img']."'alt='$name2,$product2 $price' title='$name2 $product2 £$price' width='85'></a>";
?>
<?php $row=mysql_fetch_assoc($result); // make one record out.?>
</td>
<td>
<?php // for each product show photo with a link to product page
echo "<a href='product-".$row['id']."'><img src='".$row['img']."' alt='$name2, $product2 $price' title='$name2 $product2 £$price' width='85'></a>";?>
</td>
</tr>
<?php
} // End loops.
?>
</table>
任何帮助非常感谢
答案 0 :(得分:1)
而不是使用$ product2,$ price尝试使用$ row ['product'],$ row ['price']在alt
答案 1 :(得分:0)
试试这个,但我不确定 使用此
SELECT * FROM manufacturers WHERE manuid = '$row['manuid']' ORDER BY name
而不是这个
SELECT * FROM manufacturers WHERE manuid = '$manuid2' ORDER BY name
在此之后
$row=mysql_fetch_assoc($result);
Add this line
$manu_info = mysql_fetch_assoc($manu_r);