Solved

Is is possible to execute both queries at the same time?

Posted on 2003-12-12
5
224 Views
Last Modified: 2006-11-17
At present I have this snippet code that does a little bit of cleanup on my database...

    /* Performing SQL query */
  $query_rsJobsDoPost = "UPDATE jobs SET currentbatch='0',done='y' WHERE currentbatch='2'";
  $rsJobsDoPost = mysql_query($query_rsJobsDoPost, $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
  $row_rsJobsDoPost = mysql_fetch_assoc($rsJobsDoPost);

    /* Performing SQL query */
  $query_rsJobsDoPost = "UPDATE jobs SET currentbatch='0',done='n' WHERE currentbatch='1'";
  $rsJobsDoPost = mysql_query($query_rsJobsDoPost, $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
  $row_rsJobsDoPost = mysql_fetch_assoc($rsJobsDoPost);


Is is possible to execute both queries in one go. In phpMyAdmin I can simply put...

UPDATE jobs SET currentbatch='0',done='y' WHERE currentbatch='2';
UPDATE jobs SET currentbatch='0',done='n' WHERE currentbatch='1';

as my SQL statement and it works ok. How can I do this in my PHP script?
0
Comment
Question by:davepusey
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
DoppyNL earned 125 total points
ID: 9927252
you can't do that in PHP.
You can do as many mysql_query() as you want however, so you can simply run the second right after the first.
That is also what PHPmyadmin does, it splits it up, then executes it one at a time.

this line
$row_rsJobsDoPost = mysql_fetch_assoc($rsJobsDoPost);
won't work, as it is an update query, those query's don't return results!
0
 
LVL 2

Author Comment

by:davepusey
ID: 9927287
>> this line
>> $row_rsJobsDoPost = mysql_fetch_assoc($rsJobsDoPost);
>> won't work

Well it dont cause any errors

>> You can do as many mysql_query() as you want however, so you can simply run the second right after the first.
>> That is also what PHPmyadmin does, it splits it up, then executes it one at a time.

So basically I need to do this...

/* Performing SQL query */
$query_rsJobsDoPost = "UPDATE jobs SET currentbatch='0',done='y' WHERE currentbatch='2'";
$rsJobsDoPost = mysql_query($query_rsJobsDoPost, $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
$query_rsJobsDoPost = "UPDATE jobs SET currentbatch='0',done='n' WHERE currentbatch='1'";
$rsJobsDoPost = mysql_query($query_rsJobsDoPost, $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
0
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9927299
yep

you can reduce it to this though:

$rsJobsDoPost1 = mysql_query("UPDATE jobs SET currentbatch='0',done='y' WHERE currentbatch='2'", $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
$rsJobsDoPost2 = mysql_query("UPDATE jobs SET currentbatch='0',done='n' WHERE currentbatch='1'", $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);

and if you don't need the result of the query (you are catcing the errors) you can even leave out the assignment of the result to the variable:
mysql_query("UPDATE jobs SET currentbatch='0',done='y' WHERE currentbatch='2'", $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
mysql_query("UPDATE jobs SET currentbatch='0',done='n' WHERE currentbatch='1'", $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
0
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9927306
woops, made a little mistake.
There is still a reference to the failing query-variable (wich I placed directly in the mysql_query variable).
You probably want to change that as well when you do it.

Saying that, the code you posted works just fine :)
0
 
LVL 2

Author Comment

by:davepusey
ID: 9927400
Ok, I'll stick with what I put then!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Google Maps API and PHP 25 49
Moving from Mcrypt to OpenSSL 18 45
PHP and JQuery Syntax question 4 26
Add Logo to Bookmark and Tab Headings in Browser 3 12
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question