Ways of Updating/Inserting Random dates in MySQL w

2019-09-22 08:51发布

Possible Duplicate:
How to update/Insert random dates in SQL within a specified Date Range

My MySQL database Table has the following columns:

Primary_ID, Begin_Date, End_Date, Timestamp

How do I update using phpmyadmin, selected rows with randomly generated begin_dates and timestamp within a specified date range (eg: 30 days in a month). E.g of desired outcome

Primary_id--- Begin_Date -------------Timestamp

1.------------2008-09-02--------------2008-09-02 21:48:09

2.------------2008-09-03--------------2008-09-03 15:19:01

3.------------2008-09-14--------------2008-09-14 01:23:12

4.------------2008-09-27--------------2008-09-27 19:03:59

Date Range between 2008-09-01 and 2008-09-31. Time is variable 24 hrs

I am a newbie, so a syntax that will work in phpmyadmin will help greatly.

We are making a presentation for a gym site with 500 members but the added member values all have the same begin date and time. Trying to separate them into different monthly registrations in the database, eg 50 people registered in August at different days and times, 35 people in October, etc.

When I try some of the answers here, I get this error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$randomDate = rand(1,31)' at line 1. So ideally, a code I can copy and paste into phpmyadmin with minimal editing will be appreciated. In sequence if possible. For a total dummy to understand and execute with as close to one or two clicks as possible.

1条回答
戒情不戒烟
2楼-- · 2019-09-22 09:02

I'd pull them all out with a simple MySQL call with a basic PHP script, put them into an array, run the array through a "date randomizer" and then, take the new array and update the database by ID. easy peasy. But, if can't do something this simple,you probably shouldn't be making a "presentation" for a gym. It gives the rest of us freelancers a bad name when someone can't do the basics. Not trying to be mean. Just saying, don't bite off more than you can chew.

EDIT:

Holy crap, you're whiny! I know that I'm going to regret this but here's a better breakdown (without writing it for you).

Get Database information from MySQL with PHP:

$result = //result from mysql query IE. "SELECT*FROM `database`" which results in an array of information.

Put that array through a "date randomizer" (in quotes because YOU make the function:

$num = mysql_num_rows($result);
for($i=0; $i<$num; ++$i)
{
    //run your "date randomizer" function for each date key
}

Update your Mysql with the new array that you got from your "date randomizer":

//run your MySQL query to UPDATE each rows date and information by ID

Very simple. I can't really break it down any further for you.

If your job is to write PHP, and you can't do this, you need to look for different work, regardless of your outbursts. You're a really mean person.

查看更多
登录 后发表回答