I have sort of a weird problem, so bear with me. I'm using the _remap function to implement an example.com/user/username protocol in my URI and I am using the following code:
function _remap()
{
//URI Segment I am retrieving (this part works for me)
$profile_name = $this->uri->segment(2,0);
// Query the DB where user_name (column in DB) == $profile_name
$query = $this->db->get_where('users', array('user_name' => $profile_name));
// Load user data when URI segment is retrieved, load page
foreach($query->result() as $row){
$this->load->view('user_view', $data);
}
}
So my problem is, whenever I type in an INVALID URI segment, i.e. it isn't found in the database, it just returns a blank page. I've tried a bunch of conditional statements, but basically I want this algorithm:
if $profile_name = FOUND (in DB)
display page
else
redirect to error page
Like I said, I am able to get it to accept valid DB user_name, but with an invalid one it'll just display a blank page. I figured it was because I included the 0 argument in segment(2,0) function. Let me know what you think... Thanks so much all!
P.S. Just in case you are wondering why I am not using routing features, I wasn't sure if I could do all this with routing (checking it against the DB anyway).
Just before your foreach, insert this: