Guzzyman Guzzyman - 1 year ago 70
MySQL Question

How to resolve Error 1054 in my code igniter query

I have a code igniter project hosted here but I'm having Error Number: 1054
Unknown column '' in 'on clause' displayed on the most popular section of the website.

Below is the sql query that is giving this error.

public function get_popular()
// Using active records
$this->db->select('P.*, COUNT(O.product_id) as total');
$this->db->from('orders AS O');
$this->db->join('products AS P', 'O.product_id =','INNER');
$query = $this->db->get();
return $query->result();

with this line of code coursing the issue

$this->db->join('products AS P', 'O.product_id =','INNER');

The project was working correctly on my local machine until I hosted it here for view

Answer Source

This one is quite simple. You declare an alias for the table as P - capital letter:

$this->db->join('products AS P', ...)

but then refer to it via a lower letter:

On Windows the case of the letters - P or p - doesn't matter, on Linux (which is probably used by your hosting) it does. So to fix this error just type:

$this->db->join('products AS p', 'O.product_id =','INNER');

In the future you would do well using strictly lowercase names for tables and fields as that will work on any OS.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download