Get URL Data? |
[eluser]RandyCram[/eluser]
Hello, So I am working on a rather large project and It isn't my first project with CI but my largest so far and I seem to be stuck here. I need to get data from the url and then use that data to get info from a database. Example: Mysite.com/users/profile/2 I want to get that 2 data from the url. the users and profile part are defined using the controller no problem there. I just don't know how to get that 2 information. using it in the database is no problem I just put a query in the controller to use the '$row->id;" to get the data to use in my view. Whats the best method of doing this with CodeIgniter? Thanks, Randy
[eluser]bobbob[/eluser]
Normally you would have your users controller with a function in it called profile which takes one parameter namely the 2. users.php should have this in it: Code: function profile($id)
[eluser]Dennis Rasmussen[/eluser]
/controller/method/param1/param2/... All parameters can be retrieved in your method as bobbob wrote above. If you want to make sure that the variable $id is numeric only, you can do a check manually in your method or you can specify a route requiring a number in the 3rd segment of your URL. And as a last note, you can read more about getting segment data here: http://ellislab.com/codeigniter/user-gui...s/uri.html
[eluser]RandyCram[/eluser]
Alright, i got that working and I seem to be getting an error now with my database query.. Error: Quote:A PHP Error was encountered My Code: Code: function profile($view_id) { Line #59 in my code snippet is the query.
[eluser]umefarooq[/eluser]
hi if your user_id is integer type then don't put double quotes around $view_id Code: $query = $this->db->query("SELECT * FROM profile_info WHERE user_id = $view_id"); try the above code hope will work for you.
[eluser]RandyCram[/eluser]
umefarooq, I have tried that and I get an error like this: Quote:A Database Error Occurred
[eluser]umefarooq[/eluser]
check are you getting proper value in $view_id just echo it or not if not then try Code: $this->uri->segment(3); just put you segment number
[eluser]RandyCram[/eluser]
Yup, I'm getting the right one. If i put in the echo i get the number that I have on there.
[eluser]umefarooq[/eluser]
then try this active record query Code: $this->db->select('*')->from('profile_info')->where(array('user_id'=>$view_id)); will work
|
Welcome Guest, Not a member yet? Register Sign In |