skip to Main Content

Error in getting for SQL results in codeIgniter. When I use same query in phpmyadmin I got my results successfully.
What’s wrong, please help.

MODEL:

public function calculateScore()
{
    $team_points = $this->db->query('SELECT teams.team_name,
                                        COUNT(matches.winner) AS Win
                                    FROM
                                        matches
                                    RIGHT JOIN teams ON teams.team_name = matches.winner
                                    GROUP BY teams.team_name, matches.winner
                                    ORDER BY win DESC');

    return $team_points;
}

ERROR:

{
    "conn_id": {
        "affected_rows": null,
        "client_info": null,
        "client_version": null,
        "connect_errno": null,
        "connect_error": null,
        "errno": null,
        "error": null,
        "error_list": null,
        "field_count": null,
        "host_info": null,
        "info": null,
        "insert_id": null,
        "server_info": null,
        "server_version": null,
        "sqlstate": null,
        "protocol_version": null,
        "thread_id": null,
        "warning_count": null
    },
    "result_id": {
        "current_field": null,
        "field_count": null,
        "lengths": null,
        "num_rows": null,
        "type": null
    },
    "result_array": [],
    "result_object": [],
    "custom_result_object": [],
    "current_row": 0,
    "num_rows": null,
    "row_data": null
}

2

Answers


  1. Chosen as BEST ANSWER

    Use this

    return $team_points->result();
    

    Instead of

    return $team_points;
    

  2. If you need an array as result:

    return $team_points->result_array();
    

    Or just std object:

    return $team_points->result();
    

    In addition, I think there is an error in your sql statement.
    Did you intend to write:

    ORDER BY matches.winner
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search