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

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 
); 
  • I did some modifications to your code & seems its working now, Thanks.... – Baby in Magento Dec 16 '16 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);    
  • sorry, not working for me..... – Baby in Magento Dec 12 '16 at 11:56
  • pls check this is related code : pastebin.com/iGBMuPHg – Baby in Magento Dec 12 '16 at 11:58
  • when i tried print_r($order); order table disappeared...... – Baby in Magento Dec 12 '16 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...... – Baby in Magento Dec 12 '16 at 12:04
  • sorry, table is not displaying now...... – Baby in Magento Dec 13 '16 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
}  
  • Thanks for support, i will check & come back to you..... – Baby in Magento Dec 16 '16 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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