Jump to content

Select multiple values using Db::getInstance()->executeS into simple, one dimensional array


hakeryk2

Recommended Posts

Hello dev's

 

I have probably easy question for advanced prestashop and php developers. I will show an example what I want to achieve in simpler way. Let's start with just example.

 

Currently when I want to retrieve ie all employees ID I will use: 

$employees_id = Db::getInstance()->executeS('
    SELECT id_employee FROM '._DB_PREFIX_.'employee
');

but the output that I will receive with ddd($order_employees_id) is 

Array
(
    [0] => Array
        (
            [id_employee] => 1
        )

    [1] => Array
        (
            [id_employee] => 2
        )

    [2] => Array
        (
            [id_employee] => 3
        )

    [3] => Array
        (
            [id_employee] => 4
        )

    [4] => Array
        (
            [id_employee] => 5
        )

    [5] => Array
        (
            [id_employee] => 7
        )

)

and I have to use 

$ids = array();

foreach ($employees_id as $key => $value) {
    $ids[] .= $employees_id[$key]['id_employee'] ;
}

to receive array type that I want which is

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 7
)

Maybe there is other way to acomplish that without using foreach every time? It is just much easier to operate sometimes. Any help will be very appreciated:)

Edited by hakeryk2 (see edit history)
Link to comment
Share on other sites

  • 4 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...