Being a newbie, I try to follow reputable tutorials and move forward from there. Hudzilla, has a nice tutorial on php, and one specific part, talks about how one can format (basic formatting) of mysql results into a table. I say basic, because each row simply represents one row from the database. They use the extract button to extract one row from the $results at a time. And then, you can apparently print the values from the extract function.
I used this concept on a product.php page, and here's what I came up against. I have several price breaks and their respective quantites. And these are all different for each product (including the price breaks). So basically, I need to iterate through the results, and put the price breaks into columns, then start a new row for the matching prices, and then AGAIN iterate through the results, and put the prices under their matching quantity.
However, because I'm using "extract", as shown below, I am having to re-issue the query to the database. Is there a smarter/better way to do this?
<td width="20%" bgcolor="#181EA5">Quantity</td>
<?php
$result3 = mysql_query("SELECT quantity
FROM products_pricing
WHERE item_num = '$prodID'
ORDER BY quantity", $conn);
while($myrow2 = mysql_fetch_assoc($result3)) {
extract($myrow2);
print "<TD valign=\"middle\" align=\"right\" bgcolor=\"#181EA\">$quantity</TD>";
}
?>
</tr>
<tr class="content10b">
<td width="20%">Price</td>
<?php
$result3 = mysql_query("SELECT quantity, price
FROM products_pricing
WHERE item_num = '$prodID'
ORDER BY quantity", $conn);
while($myrow2 = mysql_fetch_assoc($result3)) {
extract($myrow2);
print "<TD valign=\"middle\" align=\"right\">$$price</TD>";
}
?>
Thanks.