2

We are trying to fetch value from custom database & display related value for all rows [orders] .

but code is fetching only first row value in DB & displaying same value for all rows.

Database

enter image description here

Site

enter image description here

     foreach($order as $orderData) 
    { 
    $k = 0; 
    $orderitems = $orderData['dproduct_id']; 
    $orderitemsarray = explode(",", $orderitems); 

    while ($k < count($orderitemsarray)) 
    { 

    if ($orderitemsarray[$k] != '0') 
    { 
    $stmtorders = $user_home->runQuery("SELECT * FROM order_details"); 
    $stmtorders->execute(array(":dorder_id" => $orderData['dorder_id']));
  // $stmtorders->execute(array(":dorder_id" => $orderData['entity_id'])); 
    $roworders = $stmtorders->fetch(PDO::FETCH_ASSOC); 

    if($data['type']=="admin")continue; 

    if($data['dpaid_status']=='P'){$dorderStatus='Paid';} 
    if($data['dpaid_status']=='U'){$dorderStatus='Unpaid';} 
    if($data['dpaid_status']=='R'){$dorderStatus='Returned';} 
    if($data['dpaid_status']==''){$dpaid_status='';} 

    if ($roworders[ 

    'dproduct_id'] == '') 
    { 
    $dorderStatus = "Unpaid"; 
    } 
    else 
    { 
    $dorderStatus = $roworders['dpaid_status']; 
    } 

    $productdetail = Mage::getModel('catalog/product')->load($orderitemsarray[$k]); 
    $designer_id = $productdetail->getDesignerID() ; 

    if($accountType == "admin"){ 
    $designerName = getDesignerName($productdetail->getDesignerID()) . " -(" . $productdetail->getDesignerID() . ")"; 
    $responce[] = array( 
    $dorderStatus 
    ); 
    }

    else
    { 
    if( $designer_id== $_SESSION['userSession'] ){ 
    $designerName = getDesignerName($productdetail->getDesignerID()) . " -(" . $productdetail->getDesignerID() . ")"; 
    $responce[] = array( 
    $dorderStatus
    ); 
    } 
    }
    }

    $k++; 
    $i++; 
    } 
    }

    echo json_encode($responce);

full code : http://pastebin.com/gn4paZWM

6

3 Answers 3

1
+50

as reference to this question you need to check dproduct_id and designerorder_id against every product.

$stmt1 = $user_home->runQuery("SELECT * FROM order_details WHERE dproduct_id=:pid and designerorder_id=:doid");
    $stmt1->execute(array(
        ":doid" => $orderData->getIncrementId(),
        ":pid" => $orderitemsarray[$k],
    ));
    $paid_status='';
    while($datas = $stmt1->fetch())

{
    $paid_status=$datas['dpaid_status'];

}
$responce[] = array( 
$paid_status 
); 
1
  • I did some modifications to your code & seems its working now, Thanks.... Dec 16, 2016 at 6:52
1

AS Far as I know change this line

 $stmtorders->execute(array(":dorder_id" => $orderData['dorder_id']));

TO

 $stmtorders->execute(array(":dorder_id" => $orderData['entity_id']));

and also change this

$stmtorders = $user_home->runQuery("SELECT * FROM order_details  WHERE dorder_id=:do_id");
$stmtorders->execute(array(":do_id" => $orderData['entity_id'])); 
$roworders = $stmtorders->fetch(PDO::FETCH_ASSOC);
print_r($roworders);    
19
  • sorry, not working for me..... Dec 12, 2016 at 11:56
  • pls check this is related code : pastebin.com/iGBMuPHg Dec 12, 2016 at 11:58
  • when i tried print_r($order); order table disappeared...... Dec 12, 2016 at 12:01
  • i tried updated code : $stmtorders = $user_home->runQuery("SELECT * FROM order_details WHERE dorder_id=:dorder_id"); still order table not displaying...... Dec 12, 2016 at 12:04
  • sorry, table is not displaying now...... Dec 13, 2016 at 5:57
1
$stmtorders = $user_home->runQuery("SELECT * FROM order_details"); 
$stmtorders->execute(array(":dorder_id" => $orderData['dorder_id'])); 
$roworders = $stmtorders->fetch(PDO::FETCH_ASSOC);  

This will always get you the first row because you are always executing SELECT * FROM order_details with no where statement and because fetch always returns one row. You should call it in a while loop if you expect more rows.

So make your code like this (adapt it to your needs because I don't really understand what it should do).

$stmtorders = $user_home->runQuery("SELECT * FROM order_details WHERE dorder_id = :dorder_id"); 
$stmtorders->execute(array(":dorder_id" => $orderData['dorder_id'])); 
while ($roworders = $stmtorders->fetch(PDO::FETCH_ASSOC)) {
    //do something with $roworders
}  
1
  • Thanks for support, i will check & come back to you..... Dec 16, 2016 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.