Just the first record - 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: Just the first record (/showthread.php?tid=8807) |
Just the first record - El Forum - 06-01-2008 [eluser]Chris Williams[/eluser] I'd like to get this: Code: title field The data returned from the records has the title field in them already. But to access them I have to use a foreach statement as shown in the user guide. I supposed I could do this with multiple queries, but is it possible to reuse results from the same query? Just the first record - El Forum - 06-01-2008 [eluser]Michael Wales[/eluser] I'm not exactly sure what the question is... Your title says just the first record - to select just the first: Code: $query = $this->db->get('table', 1, 0); What your explanation sounds like is you are selecting titles and want to echo them out on at a time. For some reason you don't want to use foreach - not sure why, since that is what it is for... Code: $query = $this->db->get('table'); Of course, this code is sloppy - there should be quite a few more checks to ensure what you expect to happen is happening, but you get the idea. Just the first record - El Forum - 06-01-2008 [eluser]Chris Williams[/eluser] I guess I'm trying to write something like this Code: //just the first record (or any really since all the records name this value) Just the first record - El Forum - 06-01-2008 [eluser]Pascal Kriete[/eluser] I don't know if I understand the problem. How is it different from doing this: Code: $row1 = $query->row(); Just the first record - El Forum - 06-01-2008 [eluser]Chris Williams[/eluser] [quote author="inparo" date="1212369881"]I don't know if I understand the problem. How is it different from doing this: Code: $row1 = $query->row(); That's a good suggestion. A lot better than that I ended up with: Code: <?php foreach($query->result() as $row): ?> Which seems to work fine, if a bit hacky. :-) Thanks! |