Welcome Guest, Not a member yet? Register   Sign In
sql shorthand not working for me
#1

[eluser]battlemidget[/eluser]
Code:
function get_product_by_id($id)
    {
      $this->db->select('product.*')->from('product')->where('product.id', $id);
      $query = $this->db->get();
      return $query->result();
    }

error:
Code:
A Database Error Occurred
Error Number: 1054

Unknown column 'product.*' in 'field list'

SELECT `product`.`*` FROM (`product`) WHERE `product`.`id` = '440'

sql:
Code:
mysql> select product.* from product where product.id = '440';
+-----+-------------+---------------------------------+-------------------------------+-------------------------------------+-------+----------+
| id  | category_id | description                     | image_name                    | image_thumb                         | price | in_stock |
+-----+-------------+---------------------------------+-------------------------------+-------------------------------------+-------+----------+
| 440 | 12          | Cable Neck Button Seater - Gray | Cable Neck Button Sweater.JPG | Cable Neck Button Sweater_thumb.JPG | 48.00 | TRUE     |
+-----+-------------+---------------------------------+-------------------------------+-------------------------------------+-------+----------+


What exactly am i doing wrong?

$ pacman -Q mysql apache php
mysql 5.1.38-1
apache 2.2.13-2
php 5.3.0-3

CI 1.7.2

EDIT:

I've also done this very same thing on another CI project and it worked:

Code:
function getPropertyBySearch($loc, $p_start, $p_end, $bed)
    {
        // build join query for items above
        // give us a good clean interface for
        // customers to browse through
        $this->db->select('properties.*, locations.id as lid');
        $this->db->from('properties');
        $this->db->where('location_id',$loc);
        $this->db->where('properties.bedroom',$bed);
        $this->db->where('properties.rent >=', $p_start);
        $this->db->or_where('properties.rent <=', $p_end);
        $this->db->join('locations', 'locations.id = properties.location_id');
        $query = $this->db->get();

        return $query->result();
    }

All settings are the same and both run on virtual ips on same box.
#2

[eluser]guillermo, out of repose[/eluser]
[pre]
function get_product_by_id($id)
{
$this->db->select('*')->from('product')->where('id', $id);
$query = $this->db->get();
return $query->result();
}
[/pre]
#3

[eluser]battlemidget[/eluser]
Thanks but my problem is trying to deal with sql shorthand syntax
#4

[eluser]guillermo, out of repose[/eluser]
Haven't tried this, but give it a shot and see what happens. More on the second parameter of the $this->db->select() can be found in the user guide:

[pre]
function get_product_by_id($id)
{
$this->db->select('product.*', false)->from('product')->where('product.id', $id);
$query = $this->db->get();
return $query->result();
}
[/pre]
#5

[eluser]battlemidget[/eluser]
[quote author="guillermo, out of repose" date="1253752582"]Haven't tried this, but give it a shot and see what happens. More on the second parameter of the $this->db->select() can be found in the user guide:

[pre]
function get_product_by_id($id)
{
$this->db->select('product.*', false)->from('product')->where('product.id', $id);
$query = $this->db->get();
return $query->result();
}
[/pre][/quote]

This works! Thanks for the quick response!

-adam




Theme © iAndrew 2016 - Forum software by © MyBB