![]() |
easy way (!) to convert result of get() into a string? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: easy way (!) to convert result of get() into a string? (/showthread.php?tid=12764) |
easy way (!) to convert result of get() into a string? - El Forum - 10-30-2008 [eluser]sparbier[/eluser] I merely want to put the users email-address on the page, so I query the database only for the e-mail field by comparing with the id in the sessions userdata, which results in one single field in one single row. Now that query result is in the special format of CI, i.e. apparantly I can not directly treat it just as an array (error reads something like "cannot treat CI_DB... as array") or straightforward as a string. The code below does work, but it looks a bit stupid to me to go through a foreach if I know already that there is only one row. any suggestions? Code: $i = $this->session->userdata('id'); easy way (!) to convert result of get() into a string? - El Forum - 10-30-2008 [eluser]LDMajor[/eluser] Code: $i = $this->session->userdata('id'); you always can write a function that will do it for you =\ easy way (!) to convert result of get() into a string? - El Forum - 10-30-2008 [eluser]Jamie Rumbelow[/eluser] Instead of running result() on your get() object, run row() and that will return the object directly. easy way (!) to convert result of get() into a string? - El Forum - 10-30-2008 [eluser]dcunited08[/eluser] [quote author="Jamie Rumbelow" date="1225404470"]Instead of running result() on your get() object, run row() and that will return the object directly.[/quote] Code: $i = $this->session->userdata('id'); I would add a test to make sure that there is only one result. easy way (!) to convert result of get() into a string? - El Forum - 10-31-2008 [eluser]sparbier[/eluser] thanks all! Code: echo $this->db->get()->row()->email; |