![]() |
DB Query Return issue - 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: DB Query Return issue (/showthread.php?tid=38159) |
DB Query Return issue - El Forum - 01-31-2011 [eluser]Unknown[/eluser] Hello CI Forums. I am fairly new to CodeIgniter, and recently decided to switch over to it to make developing in PHP easier. For the CI site I'm developing right now, I have one Controller, bachmax.php. It's supposed to, and from the looks of it, successfully loads the Model Data and the View home (data array passed to it). Code: <?php There's also the Model, data.php. The functions are supposed to pull a title and body of a notice IF they exist, and pass it back to the Controller. Code: <?php Finally, here's the snippet of the notice box from the View. Code: <?php if($notice_title && $notice_body):?> The database is queried, and the code works in a sense that it returns something if it's there. But all it returns - literally - is "Array." I've checked through the User Guide for the past couple of hours to see if anything was incorrect, but I can't find anything that solves the problem. Any help would be greatly appreciated. Thanks! DB Query Return issue - El Forum - 01-31-2011 [eluser]Twisted1919[/eluser] Of course it is returning an array() because you are doing it wrong, you don't query a single row, you query the entire table, therefore it might return an array of results. so here is how you can do it: Code: <?php Read the user guide regarding the database query results and the way they are formatted when returned. DB Query Return issue - El Forum - 01-31-2011 [eluser]Unknown[/eluser] Thanks. I wasn't completely sure about the return on row() and result(). It works great. ![]() DB Query Return issue - El Forum - 01-31-2011 [eluser]cideveloper[/eluser] This really cleans up your notice_title function Code: function notice_title() and why are you querying notice table twice, once to get the title and once to get the body? Couldn't you just do this model Code: function notice_title_body() controller Code: function index() view Code: <?php if($notice):?> |