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
https://forums.phpfreaks.com/topic/218570-globally-resetting-a-table-field/
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;

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...)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.