Query: Update two tables

Hey guys,

I’m using this query:
[php]$query=“UPDATE frontlin_manager.options SET ques_id = ‘$period’”;[/php]

But, I also need to update another table in the same query:
[php]UPDATE frontlin_manager.questions SET id = ‘$period’[/php]

Is this possible?

Thanks!!

Yeah, you can use it. But I see a problem in your syntax. Here is the correct syntax for SQL UPDATE.

UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value;

Thanks for your reply!

I’m not very good at those syntaxes, could I get some help with mine?

ok. tell me the column names that you want to update in a table.

Tables: options, questions

in options
column: id

in questions
column: ques_id

I want the value $period in both tables/columns.

THANKS alot!!! I really appreciate it.

Do you want to update the value of id and ques_id or this will serve as WHERE clause??

What kind of datatype (value) is stored in the variable $value?

Hi,

I want to update the value of id and ques_id
Numbers will be stored in these, e.g. 10. (type int11 in the db)

According to what you need Your query will be:

[php]
$query = "UPDATE options SET id = $value WHERE column_name = ‘$row_value’ ";
[/php]

You haven’t mentioned any condition therefore, I have used generic column name and variable name, please change it. and It’s strange that you are updating the id column as it might be Primary Key. You need to consider what you want to update.

Hey!

Thanks for your help!

Though this code only updates the table “options” but I need it to update two tables, also the “questions” table. Like two UPDATE in the same $query if you know what I mean.

Thanks again!

Just add another query like.

[php]$query = "UPDATE questions SET ques_id = $value WHERE column_name = ‘$row_value’ ";[/php]

This made the trick:
[php]$query=“UPDATE questions, options SET questions.id = $period, options.ques_id = $period”;[/php]

Thanks a lot for your help! Appreciate it :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service