Re: updating some records in a table

2003-02-10 Thread Zak Greant
On Wed, Jan 15, 2003 at 02:07:42AM -0800, Admin-Stress wrote:
 Hi,
 
 I am new to mySQL, so I need some help. 
 I have a table, which has record structure like this:
 
 - customer
 - name
 - register_date
 - expired
 
 Every day, I add some records, new customers. The field 'expired' is just a flag, 
either '1' or
 '0'. If register_date is 3 months ago then expired = 1.
 
 The format of register_date is unixtime, or Epoch. 
 
 How can I update the entire database, for setting the expired field ? 
 
   now = current_unixtime();
   threemonths = 3 * 30 * 24 * 60 * 60;
 
   select * from table_name where register_date + threemonths  now

  Hello Admin-Stress,

  You can use an UPDATE query to modify one or more fields based on
  where criteria.

  Something like this query should meet your needs:

  UPDATE table 
SET expired = 1 
WHERE expired = 0 AND register_date  NOW() - INTERVAL 3 MONTH;

  For more information, check the MySQL manual (http://mysql.com/doc/en)
  and review the sections on UPDATE queries and DATE functions.


  Cheers!
-- 
 Zak Greant [EMAIL PROTECTED] | MySQL Advocate |  http://zak.fooassociates.com

Using and Managing MySQL
  MySQL Training: Stuttgart, May 19-23, 2003
  Visit http://mysql.com/training for more information

EFF: Protecting Freedoms on the New Frontier (http://eff.org)

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




updating some records in a table

2003-01-15 Thread Admin-Stress
Hi,

I am new to mySQL, so I need some help. 
I have a table, which has record structure like this:

- customer
- name
- register_date
- expired

Every day, I add some records, new customers. The field 'expired' is just a flag, 
either '1' or
'0'. 
If register_date is 3 months ago then expired = 1.

The format of register_date is unixtime, or Epoch. 

How can I update the entire database, for setting the expired field ? 

  now = current_unixtime();
  threemonths = 3 * 30 * 24 * 60 * 60;

  select * from table_name where register_date + threemonths  now

How to construct the proper select statement ? I use VARCHAR for register_date.

  select 
  for i = 0 to number_of_rows do
  update table_name set expired = 1;

I just could not think how to implement this. 

I need some example code how to update some records in table like in my situation. 

I use C ... or Perl 

Thanks. 

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php