Welcome Guest, Not a member yet? Register   Sign In
query result into array
#1

[eluser]FabricioFirmino[/eluser]
Hi!

I've searched in this forum if there is a way to query result to be a array of arrays (not a array of objects) although i can't find a function like it.

Who know if is there this resource in datamapper?

thanks!
#2

[eluser]Jamie Rumbelow[/eluser]
Hi Fabrico,

Could you be more specific? Do you want this functionality in CodeIgniter itself, or the DataMapper Library?

Jamie
#3

[eluser]Kenshiro[/eluser]
instead of using $query->result(), use $query->result_array() instead Smile and you get your associative array !
#4

[eluser]FabricioFirmino[/eluser]
OK, i'll try.

I'm using datamapper to model.

To view i'm using template engine, like the example bellow.


Code:
<html>

<body>

{people}
   {name}
   {age}
{/people}

<body>

</html>



But datamapper return for me an array of objects person. In template i can't do {person->name} and {person->age}

is there a way to datamapper return an array of people like example bellow:

array ( array('name'=>'Jamie','age'=>'24'), array('name'=>'wellington', 'age'=>'42') );

If possible, i can put a datamapper result with engine template without any transformation.

Thanks
#5

[eluser]Kenshiro[/eluser]
Ok nevermind i thought you were using something like active record (or the vanilla DB class from CI) from what i read datamapper is OOP only....


Edit: if you are using this version of datamapper try this :

http://www.overzealous.com/dmz/pages/ext...array.html

It allows to convert your data to arrays. Hope it helps !
#6

[eluser]FabricioFirmino[/eluser]
Thanks Summer Student, but I am not using this version of datamapper. My version is http://stensi.com/datamapper/.

I'm think if is possible to use objects in template engine ( {person->name} ). Who know talk about it?
#7

[eluser]FabricioFirmino[/eluser]
Sorry, change "Summer Student" in my last post for Kenshiro.
#8

[eluser]cahva[/eluser]
You should really use the Overzealous version of datamapper. Its in active development(Stensi's datamapper was last updated in 2008) and has many improvements over the original.
#9

[eluser]FabricioFirmino[/eluser]
You convince me to use other version, i didn't know that Stensi's version is not updated.


Thank you kenshiro for show me the overzealous and cahva for show me precious informations about boths datamappers .
#10

[eluser]danmontgomery[/eluser]
Just a side note here, you can always cast objects as arrays (and the other way around):

Code:
$foo->key = 'bar';
$foo = (array)$foo;
// $foo['key'] == 'bar'

$bar = array('key' => 'bar');
$bar = (object)$bar;
// $bar->key == 'foo'

http://php.net/manual/en/language.types....ggling.php




Theme © iAndrew 2016 - Forum software by © MyBB