Jump to content

Recommended Posts

Hello --

First let me say that I've gotten a ton of help on here, & I really appreciate it! Especially how fast everyone is to respond. In response, I've been trying to help others as much as possible with my meager PHP skills, and plan to make a donation this week to help with server costs.

Right now I'm working on a housekeeping function, to go at the beginning of my index pages, which would look through the user database, find all occurrences where the user's account_expiration_date has passed, and if it has, would change a boolean flag in another field to the value for account_is_expired. This prevents people from logging in whose accounts have expired, and flags them for the administrator to deal with.

First of all, I'm not sure if I'm approaching this correctly, to put this in as a "housekeeping" function at the top of the user & admin index pages.

Second, the code I've been using is simply changing ALL accounts to account_is_expired instead of only the expired ones. My first attempt was to select ALL users, then check all the account_expire fields, then try to return the expired ones (changed all users to expired there, too). It has been changing all morning, but my most current attempt is:

[code]

$today = time();

$query = "SELECT account_expire FROM user WHERE account_expire < $today";
$result = mysql_query($query);

while (list($account_expire) = mysql_fetch_row($result))
    {

    $query = "UPDATE user SET confirmed = '2' WHERE ($account_expire < $today)";
        $result = mysql_query($query);
    }

[/code]

All of my stored times are php timestamps (which has been working best for me so far). Thanks so much for any help or advice!

Wendy
Not really used dates much myself, so not exaclty sure how they are evaluated.

However:
[code]
$today = time();

$query = "SELECT account_expire FROM user WHERE account_expire < $today";
$result = mysql_query($query);

while (list($account_expire) = mysql_fetch_row($result))
    {

    $query = "UPDATE user SET confirmed = '2' WHERE ($account_expire < $today)";
        $result = mysql_query($query);
    }
[/code]


I don't understand why you don't just role it all into one query?
[code]
$sql = mysql_query("Update tablename SET confirmed = '2' where account_expire < '$today';");
[/code]

Course, i may be totally wrong with that just there, but looks okay to me!
Um, [sheepishly] that worked great!

For some reason I have recently had a mental lapse that causes me to think all the time I need a double-query when I [b]don't[/b]. The other day I did this & after I took a break & came back, I thought, "what am I doing?". I'm awfully tired of this project, but it has been invaluable for learning.

Thank you!
Wendy


[!--quoteo(post=383838:date=Jun 14 2006, 08:57 AM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 14 2006, 08:57 AM) [snapback]383838[/snapback][/div][div class=\'quotemain\'][!--quotec--]
could you do this however?

$query = "UPDATE `user` SET `confirmed` = '2' WHERE `account_expire` < '$today'";
$result = mysql_query($query) or die (mysql_error ());

I didn't understand the reason for the first query
[/quote]
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.