views:

61

answers:

3

I need it so that when i type in domain.com/user/1 the one gets pulled in as a variable and then can be used to get the correct database values. Right now the variable is set manually with domain.com/user . How do I setup the segments and then make get() that number. I'm working only with username url's as numbers so no, names just domain.com/user/1 , domain.com/user/487 ect

+2  A: 

Take a look at URI Routing: http://codeigniter.com/user_guide/general/routing.html

Something like:

$route['user/(:num)'] = "user/user_lookup/$1";

in your config/routes.php file will probably do what you'd like.

Billiam
I don't know what else to do.. The documentation is so one sided..
ThomasReggi
@ThomasReggi what do you mean under "what else?" the uri re-routing is the best solution for the problem you drafted in your question.
Nort
like, what other code is there? I put that in.. now what? lol
ThomasReggi
A: 

as far as I understand you can pass the segment to your model when you call it in the controller with the URI like this

$this->usermode->get_user($this->uri->segment(3));

and recieve it in your model like a parameter

function get_user($user){
$this->db->where('userid', $user);
$query= $this->db->get('user');

if($query){
return $query->result();
}else{
return false;
}
}

I hope i understand correctly what you want to do

Gerardo Jaramillo
A: 

In your controller you could have a user function:

function user($id){
    $this->db->where('userid',$id);
    $q = $this->db->get('user');
    $data['userdata']=$q;
    $this->load->view('user_view',$data);
}

This will query the user table in the database for the id passed in the url, and send the results to the user_view view. e.g. http://site.com/user/5 would query for user data that matched the userid of 5.

stormdrain