0

我有以下代码来显示来自 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 &pound;$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 &pound;$price' width='85'></a>";?>
      </td>
    </tr>
       <?php
} // End loops.
?>
</table>

非常感谢任何帮助

4

2 回答 2

1

不要使用 $product2, $price 尝试在 alt 中使用 $row['product'],$row['price']

于 2013-06-14T12:01:49.967 回答
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);
于 2013-06-15T03:53:48.863 回答