Peter23
Peter23

Reputation: 97

Preventing dynamic PHP table display correctly

I have the following code to display a block of six products from a mysql database. It displays as two columns three rows and I get individual photos and correct page links in each of the six positions but the alt tags for the three products in column one are repeated in column 2. I cannot work out why. Any thoughts, and ways to improve the code?

<?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>

Any help much appreciated

Upvotes: 0

Views: 123

Answers (2)

Bharu
Bharu

Reputation: 191

Just try this but im not sure Use this

     SELECT * FROM manufacturers WHERE manuid = '$row['manuid']' ORDER BY name

Instead of this

     SELECT * FROM manufacturers WHERE manuid = '$manuid2' ORDER BY name

After this

     $row=mysql_fetch_assoc($result);

     Add this line
          $manu_info = mysql_fetch_assoc($manu_r);

Upvotes: 0

Bharu
Bharu

Reputation: 191

Instead of using $product2, $price try using $row['product'],$row['price'] in alt

Upvotes: 1

Related Questions