Jump to content


add alias to a field after "where"

alias where field

  • Please log in to reply
3 replies to this topic

#1 Roberto Fabian Rosero Diaz

Roberto Fabian Rosero Diaz

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 09 August 2013 - 03:28 PM

good morning.
 
first clarify two things:
 
1. I am using a translator that can not speak English
2.I am using the codeigniter crud grocery.
 
I have this query with a join made ​​by active record:
    $this->db->select('dp.nom_dpto'); 
    $this->db->from('datos_factura df'); 
    $this->db->join('establecimientos es','df.id_estab = es.id'); 
    $this->db->join('ciudades ci','es.id_ciudad = ci.id_ciudad'); 
    $this->db->join('dptos dp','ci.id_dpto = dp.id_dpto');
this, obviously, to bring a field in another table and display it in the table generated by the grocery crud.
 
but when I go to the browser, and I want to edit one of the records get this error:

 

Column 'id' in where clause is ambiguous

 

SELECT `dp`.`nom_dpto` FROM (`datos_factura` df, `datos_factura`) JOIN `establecimientos` es ON `df`.`id_estab` = `es`.`id` JOIN `ciudades` ci ON `es`.`id_ciudad` = `ci`.`id_ciudad` JOIN `dptos` dp ON `ci`.`id_dpto` = `dp`.`id_dpto` WHERE `id` = '15'
 
however, I discovered that this error is that after the WHERE in the following line: `id` = '15', you have to add the alias for the table that I am using words that would read: `df`.' id `= '15' then my real question is this:
 
How do I put that "alias" in id that is after the where?
 
take into account that, as I'm using codeigniter, this should be a process unlike any sql
 
thanks for your help

 

 



#2 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 09 August 2013 - 03:50 PM

Use this fornat,

$this->db->query('YOUR QUERY HERE');

 

 

http://ellislab.com/...se/queries.html


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#3 Roberto Fabian Rosero Diaz

Roberto Fabian Rosero Diaz

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 09 August 2013 - 04:50 PM

davidoster thanks, but the problem is that the condition "where" in the query is generated from the row to which you pressed the button shaped pencil:

 

2aj408m.jpg

 

ie I can not place the "where" directly in the query, because this is supposed that automatically generates the grocery crud

 

that's the problem, so I would like to know how to enter directly modify the "where", so to place him corresponding alias



#4 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 09 August 2013 - 05:11 PM

Use unset_edit then use add_action.

 

I have no idea what you are trying to do!


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr






Also tagged with one or more of these keywords: alias, where, field

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users