Page 1 of 1

Reset Everything in SQL

Posted: Mon Aug 14, 2006 4:52 am
by psychotomus
I have a table

Code: Select all

mysql_query("CREATE TABLE Sites(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), hits_in INT(6) NOT NULL, hits_out INT(6) NOT NULL, total_in INT(7) NOT NULL, total_out INT(7) NOT NULL, site_name VARCHAR(200), site_url VARCHAR(200), banner_url VARCHAR(200), rating INT(4) NOT NULL, votes INT(4) NOT NULL, approved VARCHAR(1) NOT NULL, approved_by INT(6) NOT NULL, approved_message VARCHAR(250), username VARCHAR(30), comments INT(4) NOT NULL, description BLOB)")or die("Create table Error: ".mysql_error());

After 24 hour I want to reset all hits_in and hits_out to 0. Is this possible with 1 or 2 SQL Commands or do i have to update every entry 1 at a time?

Posted: Mon Aug 14, 2006 5:03 am
by s.dot

Code: Select all

mysql_query("UPDATE `Sites` SET `hits_in` = 0, `hits_out` = 0") or die("Error resetting stats: ".mysql_error());

Posted: Mon Aug 14, 2006 5:19 am
by psychotomus
thanks. didnt know it was like that.

Posted: Mon Aug 14, 2006 4:05 pm
by RobertGonzalez
Most people find that little trick out the hard way... by forgetting a where clause when updating a single record :evil: . Learn once, I always say... :D