![]() |
function() + mysql 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: function() + mysql problem (/showthread.php?tid=34025) |
function() + mysql problem - El Forum - 09-16-2010 [eluser]brian.89[/eluser] hy! I've got a problem: .../view/message.php : function users($srt) { $query = $this->db->query("select first_name,last_name from bw_users where id='".$str."'"); if ($query->num_rows() > 0) { $row=$query->row(); return $row->last_name . $row->first_name; } else { return "fatal error"; } } ..... <? $x=0; $query = $this->db->query("select * from bw_message where userid='".$this->session->userdata('userid')."' and label='0' order by date desc"); if ($query->num_rows() > 0) { foreach ($query->result() as $row) { ?> <tr> <td> <input type="checkbox" name="chkName"> </td> <td> <?= users($row->sent_id); ?> </td> <td> <?= $row->subject; ?> </td> <td> <?= $row->date; ?> </td> </tr> <? $x++; } } ?> users($row->sent_id); dont work ... not connected to database ![]() when: return "xy"; work... but i have database select error please help me. function() + mysql problem - El Forum - 09-16-2010 [eluser]samitrimal[/eluser] Firstly go to application/config/autoload.php and check whether database class is loaded or not.Add your controller so i can try to help u. function() + mysql problem - El Forum - 09-16-2010 [eluser]brian.89[/eluser] solution: function users($db, $str) { $query = $db->db->query("select * from bw_users where id='".$str."'"); if ($query->num_rows() > 0) { $row=$query->row(); return $row->username; } else { return "fatal error"; } } .... <?= users($this,$row->sent_id); ?> $this == database ... i give it to function(). that's work! thx function() + mysql problem - El Forum - 09-16-2010 [eluser]danmontgomery[/eluser] Actual solution: Don't make database calls in views Technical solution: Code: function users($str) { function() + mysql problem - El Forum - 09-16-2010 [eluser]brian.89[/eluser] thx! ![]() |