prepare data for display and for database - 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: prepare data for display and for database (/showthread.php?tid=19032) |
prepare data for display and for database - El Forum - 05-25-2009 [eluser]Jagar[/eluser] I've been looking for a safe way to store data in the database and then display it on the browser. I've looked at form_prep, but it does not do what I want, so I started my own function helper i.e. prep_for_database, prep_for_display,. This new functions of mine they work great on strings and array, now I'm trying to apply that to $this->db->row(), and since it's not an array, but an object I can't do anything. I would appreciate if somebody could help me out preparing the row for display especially. Thanks prepare data for display and for database - El Forum - 05-25-2009 [eluser]Jagar[/eluser] getting result_array() instead of row solves the problem, but what is the advantage of row() over result_array()? prepare data for display and for database - El Forum - 05-26-2009 [eluser]TheFuzzy0ne[/eluser] result_array() returns an array of results, row returns an object representing the first row of the result set. Generally speaking, for consistency you should use row_array() and result_array(), or row() and result(). Use row() or row_array() when you're expecting a single result, and result() or result_array() when you're expecting more than a single row. Generally, if you're expecting a single result row, you will add a LIMIT clause to your query, so the query only returns a single row. prepare data for display and for database - El Forum - 05-26-2009 [eluser]Dam1an[/eluser] Just to add to what fuzzy said about expecting single rows, you can expect a single row (and don't need the limit) if the lookup is on a unique field, such as an auto incrementing id, email, username etc prepare data for display and for database - El Forum - 05-26-2009 [eluser]Jagar[/eluser] Thanks TheFuzzy0ne and Dam1an, I'm using row_array() which works great, and now can pass the whole data for preparing for display. Thanks |