⚠ 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

Topics I've Started

display records from a table using a loop

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

add alias to a field after "where"

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



two fields .. two users .. a view

01 August 2013 - 04:07 PM

good morning
I have a question please help:
I have three tables that are:
invoices, cities, departments
in the table "invoices" I have these fields:
id (pk)
id_city (Table cities fk)
and Table "city" I have these fields:
id (pk)
id_dpt (fk departments table)
and Table "departments":
id (pk)
however, in the grocery crud controller, I'm standing on the table "invoices", I have two users: "admin" and "mauro" then the admin user will be entering fields in the table "invoices", including the "NameCity "that I bring to the table" cities ", I want the user" mauro "can see the records that I put the admin user, but this Signature: User, rather than viewing the" NameCity "I want to see the field "NameDepartament" departments table with the name of the respective department of the city to put the user "admin".
I would like you please explain how I could do this
sorry as I wrote the English, is to use a translator because I speak Spanish
thank you very much in advance