MySQL Forums
Forum List  »  PHP

Multiple queries
Posted by: Adam Kiryk
Date: March 22, 2011 10:21AM

I see other people have addressed a similar question elsewhere in this forum, but I'm still a little confused. I want to perform an update on two tables in which one table has one item updated and the other table has two items updated. How can I do this intelligently and how can I test for success? (Note that the 'story' table is updated once and the 'options' table is updated twice.

In php, I've constructed my query like this (below). It seems to work, but at the very least I'm uncertain about what I'm testing for in my test at the end:

$query= "UPDATE story SET content = '{$content}' WHERE story_id = {$id}";
$result = mysql_query($query, $connection);

$query = "UPDATE options SET option_text = '{$option1}' WHERE option_id = {$option1ID}";
$result = mysql_query($query, $connection);

$query = "UPDATE options SET option_text = '{$option2}' WHERE option_id = {$option2ID}";
$result = mysql_query($query, $connection);

// Test for success (make sure 1 row was changed)
if (mysql_affected_rows() == 1){
// success
$message = "Your edits have been made!";

Options: ReplyQuote

Written By
Multiple queries
March 22, 2011 10:21AM
March 22, 2011 12:13PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.