Queryall - How To Change The Array Key To Start From 1 Instead Of 0

I am using $command->queryAll() to get required result set from mysql database.

but it queryAll() always return array of data with index key starting from 0, is there any way which will return result set stating from different key.




[rawData] => Array

        (

            [0] => Array

                (

                    [id] => 976

                    [merchant_name] => Test1

                )


            [1] => Array

                (

                    [id] => 2433

                    [merchant_name] => Test2

                )


            [2] => Array

                (

                    [id] => 3628

                    [merchant_name] => Test3

                )


            [3] => Array

                (

                    [id] => 2368

                    [merchant_name] => Test4

                )



can I get it strt from 11 instead of 0. as below




[rawData] => Array

        (

            [11] => Array

                (

                    [id] => 976

                    [merchant_name] => Test1

                )


            [12] => Array

                (

                    [id] => 2433

                    [merchant_name] => Test2

                )


            [13] => Array

                (

                    [id] => 3628

                    [merchant_name] => Test3

                )


            [14] => Array

                (

                    [id] => 2368

                    [merchant_name] => Test4

                )



I will require it for pagination purpose in CArrayDataProvider object

Well, you could modify your [font="Courier New"]SELECT[/font] statement to look like this:




SELECT `id` + 11 AS id, `merchant_name` FROM ...



@Da:Sourcerer

:blink: I’m sure you were out of coffee …

@yii new expert

Maybe you have to do something like the following:




$rawData = $command->queryAll();

$offset = 10;

$dummy = array_fill(0, $offset, 'dummy');

array_unshift($rawData, $dummy);



This will insert 10 dummy elements before the fetched data.

I don’t know if it works for your CArrayDataProvider or not. Pagination may work, but I’m pretty sure you have to give up the sorting with this tweaked raw data. :)

So close to the truth it actually hurts :(

This will be nice idea to add dummy elements in array till offset, but I think this will lead to memory problem if offset is large like 1000 or so.

insted of this I am thinking to override CArrayDataProvider to remove array_slice method from fetchData function

[s] return array_slice($this->rawData, $pagination->getOffset(), $pagination->getLimit());

[/s]

		return $this->rawData;