There are multiple products, multiple extras for each product, and multiple options for each extra!
Which all makes for a messy html file, anyway iv completely lost myself in all the code. And now triple nested loops arent working!
First i have a switch - to show which step is in use, then a loop on the products, then a loop on the extras.
My HTML:
- Code: Select all
<!-- BEGIN product_extras -->
<form action="breeder.php?mode=order&basket=view" method="post" enctype="multipart/form-data">
<!-- BEGIN product_loop -->
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td>{product_extras.product_loop.PRODUCT_NAME}</td>
</tr>
<!-- BEGIN loop_extras -->
<tr>
<td><div class="gensmall">{product_extras.loop_extras.NAME}</div></td>
<td><div class="gensmall">{product_extras.loop_extras.FIELD}</div></td>
</tr>
<!-- END loop_extras -->
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><a href="breeder.php?mode=order&checkout=1&step=verify" class="gensmall">Continue</a></td>
</tr>
</table>
<!-- END product_loop -->
</form>
<!-- END product_extras -->
Now, my php:
- Code: Select all
$template->assign_block_vars("product_extras", array());
//* Grab Products + Check for Extras.
$sql = "SELECT * FROM breeder_baskets INNER JOIN breeder_products ON breeder_baskets.product_id = breeder_products.product_id WHERE user_id = '$userdata[user_id]'";
if(!$result = $db->sql_query($sql)){ message_die(GENERAL_ERROR, "Couldnt Find Your Basket.", '', __LINE__, __FILE__, $sql); }
$extra = 0;
while($rows = $db->sql_fetchrow($result)){
if($rows[product_extras] == 1){
$template->assign_block_vars("product_loop", array("PRODUCT_NAME" => $rows[product_name]));
$product_sql = "SELECT * FROM breeder_product_extras WHERE product_id = '$rows[product_id]'";
if(!$product_result = $db->sql_query($product_sql)){ message_die(GENERAL_ERROR, "Couldnt Find Your Basket.", '', __LINE__, __FILE__, $sql); }
while($product_extras = $db->sql_fetchrow($product_result)){
$select = "<select name=". $product_extras[extra_name] . ">";
$extra_sql = "SELECT * FROM breeder_extra_options WHERE extra_id = '$product_extras[extra_id]'";
if(!$extra_result = $db->sql_query($extra_sql)){ message_die(GENERAL_ERROR, "Couldnt Find Your Basket.", '', __LINE__, __FILE__, $sql); }
while($extras = $db->sql_fetchrow($extra_result)){
$select .= "<option value='" . $extras[extra_value] . "'>" . $extras[extra_name] . "</option>";
}
$select .= "</select>";
$template->assign_block_vars("product_extras.product_loop.loop_extras", array("NAME" => $product_extras[extra_name], "FIELD" => $select));
}
//* Show All the Extra Stuff that Needs to be Completed.
$extra = 1;
}
}
Can anyone help me and spot where i have gone wrong?
Thank you in advance for all the help! Keep up the good work guys!