php - Display only specific array elements in a foreach loop -
i have page contains ordering form, on form lists vendor information , each of products vendor underneath , in front of product input field allows user input quantity of each product want. upon submit information goes confirm page need able show order information. on form on order page have hidden field contains vendor id. , vendor id put once each vendor. need able not echo out quantity echo out vendor id specific each order. code below. first block order page , block below confirm page. stands right underneath every quantity displays vendor ids opposed 1 need.
<?php defined('c5_execute') or die("access denied."); ?> <div class="ccm-ui"><?php $db= loader::db(); //this loads database helper. loader::model('user'); //this loads user model. $u = new user(); $ui = userinfo::getbyid($u->getuserid()); //this gets user info current user. $usercostcenter = $ui->getattribute('cost_center'); //this sets variable equal attribute cost center current user. //the if statement below checks if user admin , displays info accordingly. if($usercostcenter == "admin"){ ?> <form name="selectcostcenter" action="/adminorder" method="post"> <select name="costcenter"> <option value="unitedilluminating">united illumination</option> <option value="clp">cl&p</option> </select> <input type="submit" value="continue"<button style="float:right;" type="button" class="btn btn-primary"></button> </form> <?php }elseif($usercostcenter == "united illuminating"){ ?> <form name="orderform" action="/confirm" method="post"> <?php $query = 'select * vendors costcenterid = 1'; $productquery = 'select * products costcenterid = 1'; $results = $db->getall($query); $productresults = $db->getall($productquery);?> <table class="table"> <thead> <tr> <th>quantity/product</th> <th>category</th> <th>vendor</th> <th>address</th> </tr> <?php foreach ($results $vendor) { ?> <tr class="category"> <td></td> <td><?php echo $vendor['category'];?></td> <td><?php echo $vendor['vendor'];?> </td> <td><?php echo $vendor['address'];?></td> </tr> <?php foreach ($productresults $product){ ?> <tr class="product"> <td colspan="4"><span class="name"><input type="text" name="quantities[]" size="1" /><?php echo $product['product'];?></span></td> </tr> <?php } ?> <td><input type="hidden" name="vendor[]" value="<?php echo $vendor['vendorid']; ?>"/></td> <?php }?> </table> <input type="submit" value="checkout"<button style="float:right;" type="button" class="btn btn-primary"></button> </form> </div><?php } else { ?> <form name="orderform" action="/confirm" method="post"> <?php $query = 'select * vendors costcenterid = 2'; $productquery = 'select * products costcenterid = 2'; $results = $db->getall($query); $productresults = $db->getall($productquery);?> <table class="table"> <thead> <tr> <th>quantity/product</th> <th>category</th> <th>vendor</th> <th>address</th> </tr> <?php foreach ($results $vendor) { ?> <tr class="category"> <td></td> <td><?php echo $vendor['category'];?></td> <td><?php echo $vendor['vendor'];?> </td> <td><?php echo $vendor['address'];?></td> </tr> <?php foreach ($productresults $product){ ?> <tr class="product"> <td colspan="4"><span class="name"><input type="text" name="quantities[<?php echo $vendor['vendorid']; ?>]" size="1" /><?php echo $product['product'];?></span></td> <td><input type="hidden" name="vendor[]" value="<?php echo $vendor['vendorid']; ?>"/></td> </tr> <?php } ?> <?php }?> </table> <input type="submit" value="checkout"<button style="float:right;" type="button" class="btn btn-primary"></button> </form> </div><?php } ?>
this confirm page below.
<?php defined('c5_execute') or die("access denied."); $db= loader::db(); $quantity = $_post['quantities']; $vendor = $_post['vendor']; $minimumorder = 25; foreach($quantity $num){ if ($num >= $minimumorder){ echo "$num"; echo "</br>"; foreach($vendor $vendors){ echo "$vendors"; echo "</br>"; } } } ?>
i appreciate can give. has had me stumped few days actually.
you might want rearrange array, , like:
$i = 0; foreach ($productresults $product) { echo '<input name="product['.$i.'][quantity]" />'; echo '<input name="product['.$i.'][vendor_id]" value="'.$vendor['vendorid'].'" type="hidden" />'; ++$i; }
the resulting array in $_post
have quantities & vendor separated own arrays.
Comments
Post a Comment