2013-09-24 4 views
1

주문 양식이있는 페이지가 있습니다.이 양식에는 공급 업체 정보가 나열되어 있으며 제품의 아래쪽과 아래쪽에있는 공급 업체의 각 제품은 입력 필드입니다 사용자가 원하는 각 제품의 수량을 입력 할 수 있습니다. 제출하면 정보가 주문 정보를 표시 할 수 있어야하는 확인 페이지로 이동합니다. 주문 페이지의 양식에 공급 업체 ID가 들어있는 숨겨진 필드가 있습니다. 공급 업체 ID는 각 공급 업체마다 한 번만 입력됩니다. 내가 할 수 있어야하는 것은 수량을 반향시킬뿐만 아니라 각 주문에 해당하는 공급 업체 ID를 반향시키는 것입니다. 내 코드는 아래와 같습니다. 첫 번째 블록은 주문 페이지이며 그 아래의 블록은 확인 페이지입니다. 모든 수량의 바로 아래에 서 있기 때문에 필요한 모든 공급 업체 ID가 표시됩니다.foreach 루프의 특정 배열 요소 만 표시

<?php defined('C5_EXECUTE') or die("Access Denied."); 

?> <div class="ccm-ui"><?php 


$db= Loader::db(); //This loads the database helper. 
Loader::model('user'); //This loads the user Model. 
$u = new User(); 
$ui = UserInfo::getByID($u->getUserID()); //This gets the user info for the current user. 

$userCostCenter = $ui->getAttribute('cost_center'); //This sets a variable equal to the attribute Cost Center for the current user. 

//The if statement below checks if the user is an admin and then displays the 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 * FROM Vendors WHERE costCenterID = 1'; 
     $productquery = 'SELECT * FROM Products WHERE 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 as $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 as $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 * FROM Vendors Where costCenterID = 2'; 
     $productquery = 'SELECT * FROM Products WHERE 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 as $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 as $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 
} 

?> 

아래의 확인 페이지입니다.

<?php defined('C5_EXECUTE') or die("Access Denied."); 
$db= Loader::db(); 
$quantity = $_POST['quantities']; 
$vendor = $_POST['vendor']; 
$minimumorder = 25; 

foreach($quantity as $num){ 
    if ($num >= $minimumorder){ 
     echo "$num"; 
     echo "</br>"; 
     foreach($vendor as $vendors){ 
      echo "$vendors"; 
      echo "</br>"; 
     } 
    } 
} 



?> 

누구든지 도움을 주시면 감사하겠습니다. 이것은 나를 실제로 며칠 동안 곤란하게 만들었다. 코드 $vendor['vendorID']에서

답변

0

은 그래서 당신의 확인 페이지에서 사용할 수있는 당신의 $_POST['quantities']의 키를 보인다

foreach($quantity as $vendorid=>$num){ 
    if ($num >= $minimumorder){ 
     echo "$num"; 
     echo "</br>"; 

      echo "$vendorid"; 

    } 
} 
2

당신이 당신의 배열을 재 배열 할, 그리고 같은 것을 할 수 있습니다

$i = 0; 
foreach ($productresults as $product) { 
    echo '<input name="product['.$i.'][quantity]" />'; 
    echo '<input name="product['.$i.'][vendor_id]" value="'.$vendor['vendorID'].'" type="hidden" />'; 
    ++$i; 
} 

$_POST의 결과 배열의 수량은 &이며 공급 업체는 자체 어레이로 분리됩니다.

+0

내 소스에서 이것을 정확히 구현하는 방법이 확실하지 않습니다. –

+0

나는 이것을 내 주문 페이지에 넣을 수는 있지만 그걸 어떻게 처리해야할지 모르겠다. –

+0

이와 비슷한 코드가 현재'foreach ($ productresults $ product)'를 대체 할 것이다. '$ _POST'를 덤프하면 데이터 사용 방법을 알아야합니다. –

관련 문제