Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] update query with multiple tables
#21

[eluser]maria clara[/eluser]
[quote author="flaky" date="1263402064"]it is null because $updateArray doesn't contain ','[/quote]

what do you mean by ','??
#22

[eluser]flaky[/eluser]
make this little change

Code:
foreach($crudTableName as $key => $value){ $updateArray[] = $value.'='.$crudColumnValues[$value]; };
#23

[eluser]maria clara[/eluser]
[quote author="flaky" date="1263402491"]make this little change

Code:
foreach($crudTableName as $key => $value){ $updateArray[] = $value.'='.$crudColumnValues[$value]; };
[/quote]

i have tried this.. still sad to say nothings change..
#24

[eluser]flaky[/eluser]
have you tried this
Code:
case $crudConfig['update']:
                foreach($crudTableName AS $table){
                    $this->db->where('role_id', $crudColumnValues['id']);
                    $this->db->update($table, $crudColumnValues);
                }
#25

[eluser]Dyllon[/eluser]
Maria,

You have posted several different variations of the same problem over the last few days all having to deal with undefined variables.

Now I understand that you are learning and it looks like you are trying to modify/fix an application that you did not create.
However the concept of a variable is very basic stuff and you should be able to understand what an undefined variable is and how to fix it and not run to the forum every time PHP tells you that you forgot to define a variable or that the array you are trying to use in a foreach is empty.

Asking the forum for help every time you have a minor issue is going to be an extremely slow and unproductive way to learn as people will often just feed you a solution instead of explaining the problem.

Read up on PHP and MYSQL basics, none of your issues are CI related.

When you are ready to ask a CI related question here is a good place to start http://codeigniter.com/wiki/How_to_ask_a_good_question/
#26

[eluser]maria clara[/eluser]
[quote author="Dyllon" date="1263429246"]Maria,

You have posted several different variations of the same problem over the last few days all having to deal with undefined variables.

Now I understand that you are learning and it looks like you are trying to modify/fix an application that you did not create.
However the concept of a variable is very basic stuff and you should be able to understand what an undefined variable is and how to fix it and not run to the forum every time PHP tells you that you forgot to define a variable or that the array you are trying to use in a foreach is empty.

Asking the forum for help every time you have a minor issue is going to be an extremely slow and unproductive way to learn as people will often just feed you a solution instead of explaining the problem.

Read up on PHP and MYSQL basics, none of your issues are CI related.

When you are ready to ask a CI related question here is a good place to start http://codeigniter.com/wiki/How_to_ask_a_good_question/[/quote]


hi,

thanks.
#27

[eluser]maria clara[/eluser]
[quote author="flaky" date="1263403333"]have you tried this
Code:
case $crudConfig['update']:
                foreach($crudTableName AS $table){
                    $this->db->where('role_id', $crudColumnValues['id']);
                    $this->db->update($table, $crudColumnValues);
                }
[/quote]

ive tried this and it works. i just added some scripts on it. thanks.

thanks,
maria Wink
#28

[eluser]seanloving[/eluser]
[quote author="flaky" date="1263391209"]a fast example
Code:
$this->db->where('column', $data['column_name']);
$this->db->join('table', 'table.column=table1.column1');
$this->db->update('table2', $data);
[/quote]

Hi,
I'm trying to write a query that will update some columns in the 'customers' table, some other columns in the 'contacts' table, and some other columns in the 'organizations' table. The 'customers' table has columns for 'contact_id' and 'organization_id' where I store foreign keys to their respective tables.

Here is a truncated example


Code:
$this->db->set('contacts.firstname', $data['firstname']);
            $this->db->set('organizations.organization_telephone', $data['organization_telephone']);
            $this->db->set('customers.updated_by', $this->session->userdata['user_id']);
            $this->db->join('organizations', 'customers.organization_id = organizations.organization_id');
            $this->db->join('contacts', 'contacts.contact_id = customers.contact_id'); //added
            $this->db->where('customers.customer_id', $data['customer_id']);
            $this->db->update('contacts');
            echo $this->db->last_query();exit;

I echo the generated SQL and I havn't been able to get the JOIN to work, or even to appear :down: .

Does anyone on this thread know what I'm doing wrong?
Thanks
#29

[eluser]maria clara[/eluser]
Quote:Hi,
I'm trying to write a query that will update some columns in the 'customers' table, some other columns in the 'contacts' table, and some other columns in the 'organizations' table. The 'customers' table has columns for 'contact_id' and 'organization_id' where I store foreign keys to their respective tables.

Here is a truncated example


Code:
$this->db->set('contacts.firstname', $data['firstname']);
            $this->db->set('organizations.organization_telephone', $data['organization_telephone']);
            $this->db->set('customers.updated_by', $this->session->userdata['user_id']);
            $this->db->join('organizations', 'customers.organization_id = organizations.organization_id');
            $this->db->join('contacts', 'contacts.contact_id = customers.contact_id'); //added
            $this->db->where('customers.customer_id', $data['customer_id']);
            $this->db->update('contacts');
            echo $this->db->last_query();exit;

I echo the generated SQL and I havn't been able to get the JOIN to work, or even to appear :down: .

Does anyone on this thread know what I'm doing wrong?
Thanks

hi,

can you post the errors if you have or what errors show in your console???
#30

[eluser]maria clara[/eluser]
@seanloving,

i have this code for update and it works..but it doesn't have a validation.. you can try this:

Code:
$sql = 'update '.$crudTableName.' set ';
                foreach($crudColumns as $key => $value){ $updateArray[$key] = $value.'='.$crudColumnValues[$key]; };
                $sql .= implode(',',$updateArray);
                $sql .= ' where role_id = '.$crudColumnValues['id'];
                mysql_query( $sql );

but i used $crudColumns here.

regards,
kahtrina




Theme © iAndrew 2016 - Forum software by © MyBB