我有以下代码来显示来自mysql数据库的六个产品块。
它显示为两列三行,在六个位置中的每个位置我都得到单独的照片和正确的页面链接,但是在第二列中重复了第一列中三种产品的alt标签。我不知道为什么。有什么想法和方法来改进代码吗?
<?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>
任何帮助表示赞赏
最佳答案
代替使用$ product2,$ price尝试在alt中使用$ row ['product'],$ row ['price']
关于php - 防止正确显示动态PHP表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17107638/