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

  • SEARCH
  • Home
  • 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 6850611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:08:45+00:00 2026-05-27T01:08:45+00:00

I want to clear specific row values back to null, I have a prototype

  • 0

I want to clear specific row values back to null, I have a prototype for loop that I would like to use. However I am afraid that it will delete everything in the table. The database has columns: user, password, correct, wrong, and game1, game2, game3…..game16. I want to clear the columns that start with game, but nothing else. It seems simple to do, however I cannot seem to make it work. Can someone help me understand?

$vals=array();
$sql="DELETE "; 
for ($i=1; $i<=16; ++$i) {
  if (isset(game$i)) { continue; }
  if ($i != 1) {
   $sql .= ",";
  }
  $sql .= "game$i=:game$i";
  $vals[":game$i"]="game$i";
  "game$i FROM user WHERE user = * ";
}

$statement=$db->prepare($sql);
$statement->execute($vals);
  • 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-05-27T01:08:46+00:00Added an answer on May 27, 2026 at 1:08 am

    Setting a value to NULL is an UPDATE, and different than removing the record from the database (DELETE)

    To prevent having to dynamically create you SQL Statement, it looks like you can (and probably should) just write out the whole SQL Script.

    UPDATE u
    SET u.game1 = NULL
       , u.game2 = NULL
       , u.game3 = NULL
       , u.game4 = NULL
       , u.game5 = NULL
       , u.game6 = NULL
       , u.game7 = NULL
       , u.game8 = NULL
       , u.game9 = NULL
       , u.game10 = NULL
       , u.game11 = NULL
       , u.game12 = NULL
       , u.game13 = NULL
       , u.game14 = NULL
       , u.game15 = NULL
       , u.game16 = NULL
    FROM user AS u
    

    FROM user AS u makes an alias for user, so I can reference the table with the single character u. You see this happen when I specify the UPDATE u (using the alias). W3Schools probably does a better job explaning SQL Aliases than I will.

    You do not need (and should not have) a WHERE clause if you want the UPDATE to affect all the users, this is implied by not having a WHERE

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

Sidebar

Related Questions

Here is more specific explanation of what I want to make clear: I have
Let's say I have 10 breakpoints and I want to clear one but not
First of all, I want to be clear that I'm not talking about defining
I have some beans for which, in specific injections, I want to add a
I have a live web application that is failing in one specific scenario, and
I have a method that I want to access from only one method because
Before down-voting or closing for duplicate questions, I want to make clear that I
If I have the following code (EDIT: Sorry if I wasn't clear, I want
I want to clear the list of projects on the start page...how do I
I want to clear a element from a vector using the erase method. But

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.