⚠ 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 forum is read-only and soon will be archived. ⚠

Roberto Fabian Rosero Diaz

Member Since 01 Aug 2013
Offline Last Active Aug 15 2013 08:37 PM

#8985 display records from a table using a loop

Posted Roberto Fabian Rosero Diaz on 14 August 2013 - 08:33 PM

good afternoon to all of you
please help me with this problem:
in my controller I have the following query:
            $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'); 


and sent him to the view in this way:

$this->load->view('facturas/FacturaView', $query);  

however, in the view I have a foreach loop, which is where I have to store the records that have the query, which put up, the foreach is this

foreach($sql as $row){ 
precisely within that loop is the one to display the records in a table, that's what I'd like for you to please tell me:
How do I display records from that query in this loop?



sorry for the English, not speak English and use google translator



please help, it's greatly appreciate

#8894 add alias to a field after "where"

Posted Roberto Fabian Rosero Diaz on 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->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



#8818 two fields .. two users .. a view

Posted Roberto Fabian Rosero Diaz on 06 August 2013 - 01:16 PM

davidoster hello thanks for following this topic.
I'll post an example of what I want:
in the table "city" I have the following record:
id: 001 (pk)
NameCity: Cali
id_dpto: 33 (table fk departments)
in the table "departments" I have this other record:
id: 33 (pk, which is related to the table "city")
NameDepartament: Valle del Cauca
then the user "fabian" enters the table "invoices" track, including the "NameCity" field, that would be the city "Cali", but the user "mauro" will never look at the "NameCity" field but vera the "NameDepartament" corresponding field, that is, instead of looking in the "Cali", which will see is "Valle del Cauca", since it corresponds to the city "Cali".
that's what I want to know
friend please help me with this as it is the only thing I needed to finish my project, and depend only on your answers to finish, and I can not find anything on google that I may have
sorry again for the bad translation
from already thank you very much