![]() |
Quick Question - 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: Quick Question (/showthread.php?tid=38010) Pages:
1
2
|
Quick Question - El Forum - 01-27-2011 [eluser]Wondering Coder[/eluser] Code: if($query) My problem is i'm trying to get the primary key or id in my table but don't have any luck. I know im missing something here and I know that this is very simple. Can anyone show me the light here. When echoed it, this is the result: Code: Array Quick Question - El Forum - 01-27-2011 [eluser]Cristian Gilè[/eluser] We need the query and the view code. Cristian Gilè Quick Question - El Forum - 01-27-2011 [eluser]Kindari[/eluser] What is the form you are submitting? Check the genereated form (view source) and make sure id is defined. Quick Question - El Forum - 01-27-2011 [eluser]Wondering Coder[/eluser] this is my controller function Code: function validate_credentials() Code: function my_profile() // just for sample my membership_model Code: function validate($data) Code: you are logged in what im trying to do is having a profile page but to do this i would need first the primary key or id of the user. Quick Question - El Forum - 01-27-2011 [eluser]Kindari[/eluser] Well, the id is stored in the database, correct? The id is not known when the user logs in. So user logs in, your controller grabs their username and password, then validates it. But what you need to do is instead of returning the number of rows (which in a user system should either be 1 or 0) just return the row itself, or FALSE. if False, user failed to log in. if the user did login, you return the row. so change the membership model to: Code: function validate($data) Then your if($query) should still work. Following that, id is NOT in the post, instead retrieve from row. Code: 'id' => $row->id, That should fix your problem unless I missed something else. Quick Question - El Forum - 01-27-2011 [eluser]Wondering Coder[/eluser] @Kindari first of all i want to thank you for helping me on this one ^_^. i followed what you said kindari but now it gave me this error: Undefined Variable: row and Trying to get property of non-object. Quick Question - El Forum - 01-27-2011 [eluser]Kindari[/eluser] Sorry friend I confused myself because of my own naming conventions ![]() replace $row with $query and it should work just fine. Quick Question - El Forum - 01-27-2011 [eluser]Wondering Coder[/eluser] its working now Kindari. again thanks ^ ![]() last question for tonight, if i want to pass the "'id' => $query->id" to my another controller how will i be able to do that? Then to display it to my view? Quick Question - El Forum - 01-27-2011 [eluser]stuffradio[/eluser] [quote author="Wondering Coder" date="1296178653"]its working now Kindari. again thanks ^ ![]() last question for tonight, if i want to pass the "'id' => $query->id" to my another controller how will i be able to do that? Then to display it to my view?[/quote] When you have a variable referencing your model, do it like this: Code: $data['results'] = $this->model->validate(); Quick Question - El Forum - 01-27-2011 [eluser]Cristian Gilè[/eluser] Wondering Coder, do a redirect to another controller and pass the id as parameter: Code: redirect('controller_name/method_name/'.$query->id); and then: Code: class Controller_name extends Controller alternatively, you can set a session: Code: $this->session->set_userdata('id',$query->id); // or set a flashdata if you need the id only for the next request You can then retrieve the id in the controller and in the view with Code: $this->session->userdata('id'); Cheers Cristian Gilè |