![]() |
Database results will not display. New to CI - 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: Database results will not display. New to CI (/showthread.php?tid=18095) Pages:
1
2
|
Database results will not display. New to CI - El Forum - 04-25-2009 [eluser]cpeele[/eluser] Hey guys, I am very new to codeIgniter and am trying to get my page to display some database results but no rows show. 1) I have data in my database 2) I have set autoloading 3) Here is my database configuration: Code: $db['default']['hostname'] = "localhost"; 4) Here is my Controller Code: <?php 5) Here is my view Code: <?php if($query->num_row() > 0): ?> 6) Here is my output when I do a print_r($data); Code: Array ( [query] => CI_DB_mysql_result Object ( [conn_id] => Resource id #28 [result_id] => Resource id #29 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 2 [row_data] => ) ) Please if anyone can help me I would really appreciate it. I would like to start using CI over CakePHP but I can't even get this to dispaly database results. Thanks for any help, Chris Database results will not display. New to CI - El Forum - 04-25-2009 [eluser]Stelian Mocanita[/eluser] Code: $query = $this->db->get('questions'); That will convert yout mysql resource into the array you need. Database results will not display. New to CI - El Forum - 04-25-2009 [eluser]Dam1an[/eluser] [quote author="Stelian Mocanita" date="1240694940"] Code: $query = $this->db->get('questions'); That will convert yout mysql resource into the array you need.[/quote] But he's using the query object in the view (num_rows) And he's using it as an object, not an array Changing the foreach loop to be Code: <?php foreach($query->result() as $row): ?> Database results will not display. New to CI - El Forum - 04-25-2009 [eluser]Stelian Mocanita[/eluser] My bad, didn't see the view part just use Code: $data['query'] = $query->result() That will pull an object data from the resource so you don't have to change the view file. Database results will not display. New to CI - El Forum - 04-25-2009 [eluser]Dam1an[/eluser] [quote author="Stelian Mocanita" date="1240702662"]My bad, didn't see the view part just use Code: $data['query'] = $query->result() That will pull an object data from the resource so you don't have to change the view file.[/quote] He will still have to change the view, as he calls num_rows, which is called on the query object So he either converts the query to a result after that, or uses sizeof on the results Database results will not display. New to CI - El Forum - 04-25-2009 [eluser]cpeele[/eluser] Hey guys, thanks for all the responses. I tried all your suggestions to no avail unfortunately Code: <?php I even tried using Code: $data['query'] = $query->result_array(); here's the view Code: <ul> it shouldn't be this hard to pull some data...any additional ideas would be greatly appreciated. Database results will not display. New to CI - El Forum - 04-26-2009 [eluser]Dam1an[/eluser] you now alppear to be calling ->result() on the query in the controller, and you try calling it on what is now the result (although called query in the view try Code: <?php Database results will not display. New to CI - El Forum - 04-26-2009 [eluser]cpeele[/eluser] unfortunately that doesn't appear to work either. but thanks for the help Database results will not display. New to CI - El Forum - 04-26-2009 [eluser]Dam1an[/eluser] Does that give you an error, or just doesn't have the results you expect? Database results will not display. New to CI - El Forum - 04-26-2009 [eluser]cpeele[/eluser] Hello ![]() It does't give me an error or any results ![]() |