Welcome Guest, Not a member yet? Register   Sign In
Best Practices for No Results from Database Query?
#6

[eluser]theprodigy[/eluser]
Quote:I’d prefer to only load the view if there’s something to display
Sounds like you're going to have to do some kind of decision making in your controller if you don't want to display the view if no results are found.

The only other option I can see (which I advise AGAINST), is to tighten the coupling between your model and controller, and do something like
MODEL:
Code:
$result = $this->db->get('table');
if($result->num_rows() > 0)
{
    $return['results'] = $result;
    $return['view'] = 'view_name';
}
else
{
    $return['results'] = 'No Results found';
    $return['view'] = 'error_view_name';
}
                          
return ($result->num_rows() > 0) ? $result : false;
CONTROLLER:
Code:
$entries = $this->model->function();
              
$this->load->view($entries['view'], $entries);

but since the title of this post is "Best Practices for No Results from Database Query?", I won't be offering any bad practices (like the one above)


Messages In This Thread
Best Practices for No Results from Database Query? - by El Forum - 02-08-2010, 04:02 PM
Best Practices for No Results from Database Query? - by El Forum - 02-08-2010, 05:32 PM
Best Practices for No Results from Database Query? - by El Forum - 02-08-2010, 05:52 PM
Best Practices for No Results from Database Query? - by El Forum - 02-08-2010, 06:08 PM
Best Practices for No Results from Database Query? - by El Forum - 02-08-2010, 06:16 PM
Best Practices for No Results from Database Query? - by El Forum - 02-08-2010, 06:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB