Jump to content

"globally" resetting a table field


ack

Recommended Posts

Forgive me if I am using the word "globally" incorrectly...

 

I want to reset the content of a particular field in all rows of a table to a specific value,

 

I was thinking of nesting a query inside a query for the same table, but was not sure that this would work:

 

 

...

$query = "SELECT * FROM music WHERE picked >'0'";

$result = mysql_query($query)

      or die ("Couldn't execute query.");

 

 

 

/* reset the picked field to zero (0) */

 

 

while ($row = mysql_fetch_array($result))

  {

 

  $picked = 0;

 

 

  $query= "UPDATE music SET picked='$picked' WHERE title='$title'";

  $selectresult = mysql_query($query) or die ("Problem with the query: $query<br>" . mysql_error());

  }

  ... 

 

Is this the correct approach or is there a better way of doing this?

Link to comment
Share on other sites

 $query= "UPDATE music SET picked= 0";
$selectresult = mysql_query($query) or die ("Problem with the query: $query<br>" . mysql_error());

 

If this is a one time thing, simply execute that query in your favorite database management program -

UPDATE music SET picked= 0;

Link to comment
Share on other sites

Thanks again,  PFMaBiSmAd

 

I successfully wrapped your code example into a maintenence page so that I can now reset the table when necessary.

 

I spent quite a while trying to find a solution and I suspected that I was going down the wrong road...

 

I have been researching PHP classes in my area and - from this question - it appears that spending some time in the classroom will help a lot. too!

 

I appreciate everyone's help and advice over the last few days!

 

Cordially,

 

Ack

(not the ASCII control code, BTW.  I was amazed that that handle had not been snagged onto here.  Usually that stuff is long gone...)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.