Welcome Guest, Not a member yet? Register   Sign In
Single value return "Array to string conversion?"
#3

[eluser]Sky Warden[/eluser]
[quote author="jmadsen" date="1363948530"]Even though your result() object only has one row, it is still a collection of rows. You might want to look at result_array() just to make it easier to visualize with var_dump()

The result_array() will be an array of arrays, each of those sub arrays being a row(). The function won't change up the return object simply because the requested data changes to something simpler - you have to do that yourself.

However, there are a couple things that can help:

Code:
->row()/->row_array() will grab the first row - so if you know you only have one, just use that

    ->row()->username / ->row_array()['username'] - can get a value directly

Just use them with caution - easy to make logic bugs until you're comfortable[/quote]

Whoa! Thank you! It's working now. I totally forgot that row() will grab the first row. :lol:

I know it's not relevant to the topic, but do you think it's a good idea to load models from view? Some people say it's fine, while some other don't. In some cases, I need to load it from view instead of loading it in controller then give the data to the view. Is there any disadvantage of this method?


Messages In This Thread
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 03:13 AM
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 03:35 AM
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 03:45 AM
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 03:52 AM
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 04:33 AM
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 07:09 PM
Single value return "Array to string conversion?" - by El Forum - 03-23-2013, 10:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB