Outputting data problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Outputting data problem (/showthread.php?tid=37072) |
Outputting data problem - El Forum - 12-27-2010 [eluser]skribe[/eluser] Hi folks: I'm adapting this CRUD example and I'm having some difficulties trying to determine how to output my data. Basically what it should do is output the contact details of a person which are held in three tables Person: id name Contact_Type: id type Person_contact (join): person_id contact_type_id details Contact type allows me to add different ways to contact people (email, phone, european swallows). Details holds the actual address. These are the additions. They're producing a Message: Undefined property: CI_DB_mysql_result error Controller: Code: function view($id){ Model: Code: function get_person_contact($id){ View: Code: <?php foreach ($contact as $contact){ ?> Any suggestions? Outputting data problem - El Forum - 12-27-2010 [eluser]mi6crazyheart[/eluser] Change u'r model to this... Code: function get_person_contact($id){ VIEW should be Code: foreach($contact as $item): Outputting data problem - El Forum - 12-27-2010 [eluser]skribe[/eluser] Thanks for the help. Unfortunately it's not returning any data. Even the foreach is failing to produce the html rows so $contact must be empty. Outputting data problem - El Forum - 12-27-2010 [eluser]mi6crazyheart[/eluser] Just before foreach() in VIEW add these line to check weather u'r getting any data from Db or not.. Code: echo(count($contact)); // it'll show no. of records u'r getting from DB Outputting data problem - El Forum - 12-27-2010 [eluser]skribe[/eluser] It's definitely empty. It returns: 0 Array ( ) Outputting data problem - El Forum - 12-27-2010 [eluser]mi6crazyheart[/eluser] Then i think there might've some problem in sql query. May be query is not able to match with any records... Outputting data problem - El Forum - 12-27-2010 [eluser]skribe[/eluser] [quote author="mi6crazyheart" date="1293533880"]Then i think there might've some problem in sql query. May be query is not able to match with any records...[/quote] I considered that. This query runs fine in mysql: Code: SELECT ct.type, pc.details FROM person_contact pc LEFT JOIN contact_type ct on pc.contact_id = ct.id WHERE pc.person_id = '1'; I substitute 1 with $id in php. I've substituted the active records query with this and end up with the same no result. Thanks for the help so far btw. Outputting data problem - El Forum - 12-27-2010 [eluser]cideveloper[/eluser] Take out the quotes on $id in the where clause. you have '$id' which means you are looking for '$id' in your database not the passed value enabling profiling helps a lot when you need to debug stuff Code: function get_person_contact($id){ Outputting data problem - El Forum - 12-28-2010 [eluser]skribe[/eluser] Thanks guys. Removing the quotes fixed it. Outputting data problem - El Forum - 12-28-2010 [eluser]InsiteFX[/eluser] Try this, you did not add the left at the end of your join! Code: $this->db->join('contact_type ct', 'pc.contact_id = ct.id', 'left'); InsiteFX |