Outputting data problem |
[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?
[eluser]mi6crazyheart[/eluser]
Change u'r model to this... Code: function get_person_contact($id){ VIEW should be Code: foreach($contact as $item):
[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.
[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
[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...
[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.
[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){
[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 |
Welcome Guest, Not a member yet? Register Sign In |