Hello, I am facing a problem with displaying product data from mysql into the html table format I would like. I am very new at coding, so need help.
I have a working code which displays the data in a single column html table, but when I try to display it into a 3 column table, the results are incorrect. The product table has fields such as Name, Price, Desc etc.
Desired Output:
Col1 Col2 Col3
Row 1--> Prod 1 Prod 2 Prod 3
Prod Name1 Prod Name2 Prod Name3
Price1 Price2 Price3
Row 1--> Prod 4 Prod 5 Prod 6
Prod Name4 Prod Name5 Prod Name6
Price4 Price5 Price6
..and so on
(each cell has product details of each product)
Please see my current code below. Understandably, the output of this code is repeating the data of each row across all columns, basically the column is not within the required iteration loop. I don’t know how to rectify this. Please help!
Current Output:
Col1 Col2 Col3
Row 1--> Prod 1 Prod 1 Prod 1
Prod Name1 Prod Name1 Prod Name1
Price1 Price1 Price1
Row 1--> Prod 2 Prod 2 Prod 2
Prod Name2 Prod Name2 Prod Name2
Price2 Price2 Price2
..and so on
Current Code:
<table style="text-align: left; width: 100%;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<?php if($row = mysql_fetch_array($result)){do{?>
<tr style="font-family: Trebuchet MS; font-size: small; color: rgb(0, 0, 255);">
<?php for ( $counter = 1 ; $counter <= 3; $counter += 1) {?>
<td>
<?php
$desc = $row["description"] ;
$short_desc = substr($desc, 0, 50) ;?>
<img src="<?php echo $row["aw_thumb_url"];?>" alt="<?php echo $row["product_name"];?>" />
<br>
<?php echo $row["product_name"];?>
<br>
<?php echo $short_desc;?>
<br>
<?php echo $row["search_price"];?>
<br>
<a href="<?php echo $row["aw_deep_link"];?>">Purchase</a>
<br>
</td>
<?php } ?>
</tr>
<?php } while($row = mysql_fetch_array($result));
} ?>
</tbody>
</table>
Please let me know how I can get the desired output, with minimal changes (if possible) to this code. Will be very grateful. Thanks.