one random number per day

Theonomy

New member
Hey guys.

I know it's been a while since previous posts were written, but while googling around I found it and I used it to make simple thing. I used following code:

Code:
    if ($row['Date'] != date("Y-m-d")) {
         //Then it must be the next day
         $Number = 0;
         while($Number == $row['Number'] || $Number == 0) { //Keep looping through until we really get a new number
             $Number = rand(0,10); //0 is Minimum, 10 is Maximum. Adjust as necessary;
         }
         //We have a new number now, so just save it to the database and we are done
         $novisql = "Update RandomNumber set Date = 2024-04-06, Number = ".$Number."";
            if ($conn->query($novisql) === TRUE) {
                echo "Record updated successfully";
            } else {
                echo "Error updating record: " . $conn->error;
            }
    } else {
        $Number = $row['Number'];
    }
    //OK, we now have our random number `$Number` and the database is up to date

Do note that the query is updating Number at every load, while my Date field in database is always 0000-00-00. Whatever I write in sql query it's the same. Not really sure what I'm doing wrong, maybe I did something wrong in database itself, I just used type date for that field?

Any help would be appreciated!
 
Back
Top