Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

php - SQL increment index and update column every week

I have a table named the_week with 2 columns (week, id)
I'm using this SQL script to store to the db.
UPDATE the_week SET week = 0 WHERE id = '0'

To share more of my project I'm using wordpress so the usage is more with $wpdb

Basically, I want to increment the value every Thursday and save it to the db.

  <?php $today = date("l"); ?>

  <?php if ( strtolower($today) == 'thursday' ) { ?>
      <?php $week_index++; ?>
      <?php $wpdb->query( "UPDATE the_week SET week = $week_index WHERE id = '0' " ); ?>
  <?php } ?>

Now I'm doing something wrong here because this code is running when the user visits the website and of course I don't need it to rely on that.

How can I do that?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you can use a cron job if you are on live server you can create a cron job to hit on every thursday and hit that script which contain the code of updating the values


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...