简体   繁体   中英

Array Return always the same value

I don't find the solution how to resolve this point

var_dump($orders_status_support_array[$value['orders_status_support_id']]);

return always the same value

thank you.

                $QordersHistory = $this->app->db->prepare('select orders_status_support_id,
                                                                  orders_status_history_id
                                                            from :table_orders_status_history
                                                            where orders_id = :orders_id
                                                            order by date_added desc
                                                           ');
                $QordersHistory->bindInt(':orders_id',$oID);
                $QordersHistory->execute();

$order_array = $QordersHistory->fetchAll();

foreach ($order_array as $value)
{
    $QordersStatusSupport = $this->app->db->prepare('select orders_status_support_id,
                                                                 orders_status_support_name
                                                           from :table_orders_status_support
                                                           where language_id = :language_id
                                                            and orders_status_support_id = :orders_status_support_id
                                                          ');    
    $QordersStatusSupport->bindInt(':language_id', $CLICSHOPPING_Language->getId());
    $QordersStatusSupport->bindInt(':orders_status_support_id', $value['orders_status_support_id']);
    $QordersStatusSupport->execute();

    $orders_status_support_array[$value['orders_status_support_id']] = $QordersStatusSupport->value('orders_status_support_name');
}

result of : var_dump(orders_status_support_array)

array(3) { [2]=> string(7) "Pending" [4]=> string(8) "Resolved" [3]=> string(7) "Process" } array(3) { [2]=> string(7) "Pending" [4]=> string(8) "Resolved" [3]=> string(7) "Process" } array(3) { [2]=> string(7) "Pending" [4]=> string(8) "Resolved" [3]=> string(7) "Process" 

result of: var_dump($orders_status_support_array[$value['orders_status_support_id']]);

string(7) "Process" string(7) "Process" string(7) "Process"

var_dump($value)

array(2) { ["orders_status_support_id"]=> string(1) "2" ["orders_status_history_id"]=> string(2) "15" } array(2) { ["orders_status_support_id"]=> string(1) "4" ["orders_status_history_id"]=> string(2) "14" } array(2) { ["orders_status_support_id"]=> string(1) "3" ["orders_status_history_id"]=> string(2) "13" } string(7) "Process" array(2) { ["orders_status_support_id"]=> string(1) "2" ["orders_status_history_id"]=> string(2) "15" } array(2) { ["orders_status_support_id"]=> string(1) "4" ["orders_status_history_id"]=> string(2) "14" } array(2) { ["orders_status_support_id"]=> string(1) "3" ["orders_status_history_id"]=> string(2) "13" } string(7) "Process" array(2) { ["orders_status_support_id"]=> string(1) "2" ["orders_status_history_id"]=> string(2) "15" } array(2) { ["orders_status_support_id"]=> string(1) "4" ["orders_status_history_id"]=> string(2) "14" } array(2) { ["orders_status_support_id"]=> string(1) "3" ["orders_status_history_id"]=> string(2) "13" } string(7) "Process"

I think your issue might be a key issue...

Basically, you're looking for:

$orders_status_support_array[2]

2 is the index as orders_status_support_id in $value is 2.

The 3rd element, or index 2 [0,1,2] in the $orders_status_support_array is "Process" so it looks like it may not be respecting your index numbers, and rather treated them sequentially.

Are you able to test this theory by including all status' in $orders_status_support_array rather than just the 3 you are including, and order them correctly?

For example:

0 => "Other Status 1"
1 => "Other Status 2"
2 => "Pending"
3 => "Process"
4 => "Resolved"

Currently, the first 2 elements seem to be missing, and elements 4 and 3 are the wrong way around.

Tidy the array, include the other status' have them in a normal key order, ie, 0, 1, 2, 3, 4 etc. and you should find it easier to get this working.

Does that make sense?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM