[eluser]alboyd[/eluser]
Quote:Code:
class NextComp extends Model {
function index()
{
$datetoday = time();
$query = $this->db->query('
SELECT CompName
, CompFormat
, CompDate
FROM clubcompetitions
WHERE CompDate + 86399 >= $datetoday
ORDER BY CompDate ASC
LIMIT 0, 1');
return $query();
}
}
The main problem with this is that the query is asking to select WHERE CompDate + 86399 >= $datetoday. I think you would prefer it actually evaluate against the value of $datetoday rather than the literal string of "$datetoday".
If you have a variable within single quotes it remains as the letters of the variable name. If you use double quotes it expands out the variable and replaces with the value of the variable.
IMO: Also.. I would remove the Camelcase from your field names - gonna cause pain at some point I'd reckon.
Your model would also normally hold more than one function so I'd suggest you want to do something like:
Code:
class Competitions extends Model {
function next_comp()
{
$datetoday = time();
$query = $this->db->query('
SELECT compname,
compformat,
compdate
FROM clubcompetitions
WHERE compdate + 86399 >= ?
ORDER BY compdate ASC
LIMIT 0, 1', $datetoday);
return $query;
}
}
Also just realised you were returning $query() instead of $query.
EDIT: Wow just did some more reading of the thread so far.. Seems you have a few more things going wrong here.
In your controller, using my model as shown above you would do something like this:
Code:
$this->load->model('Competitions');
$results = $this->Competitions->next_comp();
if ($results->num_rows() > 0)
{
// do stuff with the data returned
}
else
{
// deal with the fact no data was returned
}