⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

add alias to a field after "where"



Roberto Fabian Rosero Diaz

Roberto Fabian Rosero Diaz
  • profile picture
  • Member

Posted 09 August 2013 - 15: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

 

 


davidoster

davidoster
  • profile picture
  • Member

Posted 09 August 2013 - 15:50 PM

Use this fornat,

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

 

 

http://ellislab.com/codeigniter/user-guide/database/queries.html


Roberto Fabian Rosero Diaz

Roberto Fabian Rosero Diaz
  • profile picture
  • Member

Posted 09 August 2013 - 16: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


davidoster

davidoster
  • profile picture
  • Member

Posted 09 August 2013 - 17:11 PM

Use unset_edit then use add_action.

 

I have no idea what you are trying to do!