Welcome Guest, Not a member yet? Register   Sign In
Attempting my 1st model... but beginning to struggle!
#8

[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
}


Messages In This Thread
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-29-2009, 09:50 AM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-29-2009, 12:31 PM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-30-2009, 05:14 AM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-30-2009, 05:26 AM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-30-2009, 05:41 AM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-30-2009, 05:43 AM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-30-2009, 05:49 AM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-30-2009, 08:49 AM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-30-2009, 10:38 AM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-30-2009, 08:49 PM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-30-2009, 11:40 PM
Attempting my 1st model... but beginning to struggle! - by El Forum - 10-31-2009, 05:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB