Jump to content

Recommended Posts

I have an online store that was created with PHP and it uses MySQL on the backend.

There’s a boolean field in the database that either turns the store on (enabled) or it turns the store off (disabled) when it’s toggled.

My question is can I write code that would automatically toggle that boolean value at specific times of the day?

Link to comment
https://forums.phpfreaks.com/topic/311006-switch-boolean-value-with-timer/
Share on other sites

Can you tell me more about how to do it or is there a place where I can detailed information?

I’ll be using a standard Linux OS at a web hosting company.

I familiar enough to modify PHP or MySQL or follow instructions, but I’m still relatively new to both.

Edited by MysticKnight
21 minutes ago, MysticKnight said:

They only sell products that have to be picked up in person

So someone can't order something to be picked up tomorrow?   I do that somewhat frequently with lowes/home depot.

 

In any case, you'd essentially just create a script to change that field.

<?php

$online = intval($argv[1]);
$db = new PDO('mysql:host=localhost;dbname=store', 'username', 'password');
$statement = $db->prepare('UPDATE table SET online=? WHERE whatever');
$statement->execute([$online]);

Then setup two cron jobs to run that script at whatever time you want to toggle the field and it's desired value

# Set online=1 at 9am
0 9 * * * /usr/bin/php /home/you/toggleOnline.php 1
# Set online=0 at 5pm
0 17 * * * /usr/bin/php /home/you/toggleOnline.php 0

You'll have to get more sophisticated if you want to handle things like weekends, holidays, etc.

Edited by kicken

I can’t thank you enough for your help. I’m going to use your suggestion and see if I can get it working tomorrow.

I know it sounds weird, but in this case they want the shopping cart to turn off when someone isn’t available to immediately follow up on the order by phone.

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.