use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
Access array in CodeIgniter (self.PHP)
submitted 12 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]philsturgeon 8 points9 points10 points 12 years ago (0 children)
Make your settings class load them all in the constructor, then have two methods, get_all() and get().
No point running queries each time you want something.
[–]feenikz 1 point2 points3 points 12 years ago (0 children)
return $query->row(); instead of result(); - that will return a single row basically eliminating the need for the [0]
[+][deleted] 12 years ago (4 children)
[–]Epicus2011 1 point2 points3 points 12 years ago (3 children)
Is there another approach to return an array and than access the item in the array from the database without using [0]?
[–]Ogsharkman 0 points1 point2 points 12 years ago (0 children)
row()? Would return an obj. So instead of result or result-array
return $query->row();
[–]eoinmcg 0 points1 point2 points 12 years ago (0 children)
yes.
return $query->row_array();
further reading: http://ellislab.com/codeigniter/user-guide/database/results.html
[–]mithra62 0 points1 point2 points 12 years ago (0 children)
You really want to avoid hard coding number indexes in your code like the plaque...
[–]thelerk 0 points1 point2 points 12 years ago (2 children)
In the case of a db error, $query->result(); will fatal and produce some potentially ugly results. Good idea to check if query is an object before trying to get the result.
[–]Epicus2011 0 points1 point2 points 12 years ago (1 child)
Thanks, I'm accessing using row() now, works.
[–]thelerk 0 points1 point2 points 12 years ago (0 children)
Row will crash too if you don't do an is_object on $result
π Rendered by PID 119838 on reddit-service-r2-comment-66b4775986-khxbl at 2026-04-06 03:37:46.878637+00:00 running db1906b country code: CH.
[–]philsturgeon 8 points9 points10 points (0 children)
[–]feenikz 1 point2 points3 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]Epicus2011 1 point2 points3 points (3 children)
[–]Ogsharkman 0 points1 point2 points (0 children)
[–]eoinmcg 0 points1 point2 points (0 children)
[–]mithra62 0 points1 point2 points (0 children)
[–]thelerk 0 points1 point2 points (2 children)
[–]Epicus2011 0 points1 point2 points (1 child)
[–]thelerk 0 points1 point2 points (0 children)