Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8553405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:38:38+00:00 2026-06-11T14:38:38+00:00

Using PHP and MySQL, I have a query that will look something like this:

  • 0

Using PHP and MySQL, I have a query that will look something like this:

UPDATE mytable 
   SET status='$newstatus' 
 WHERE (col1='$col1[0]'AND col2='$col2[0]') 
   OR (col1='$col1[1]'AND col2='$col2[1]') 
   OR (...);

I actually need to record the current ‘status’ of each of these rows before the update. Do I need to do a separate SELECT before this, or can (should / how would) I combine the two queries?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:38:39+00:00Added an answer on June 11, 2026 at 2:38 pm

    You cannot get that from this query (you could only get number of affected rows, but that’s it). If you need that, you shall first do SELECT on your conditions like:

    SELECT `id` FROM `mytable`
    WHERE (`col1`='$col1[0]' AND `col2`='$col2[0]')
       OR (`col1`='$col1[1]' AND `col2`='$col2[1]')
       OR (...)
    

    and then do UPDATE with WHERE using fetched ids. I do not recommend doing UPDATE with your current WHERE clause as in meantime (between your SELECT and UPDATE) db content could change, so you could be UPDATING different rows that you had SELECTed. Or use table locking (but I do not think it makes sense here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple query (in a mySQL view) that php is using to
I am building a website using php and mysql.I have a login that is
Assume that I have login to system using PHP + MySQL, then, after I
I have a table with records that look like this: CREATE TABLE sample (
I've been struggling with this query for a few days now. I'm using PHP/MySQL.
This is for MySQL and PHP I have a table that contains the following
using php and mysql I have two tables, a users table and a profiles
Using PHP / MySQL all encoded up as UTF, we have recently had to
I'm using PHP/MySql. If I have two tables (hypothetically) as follows: id name and
i have created a forum using php/mysql and users login through facebook using php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.