mysql 插入指定时间_在特定日期和时间范围内在MySQL中更新/插入随机日期的方法...

bd96500e110b49cbb3cd949968f18be7.png

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.

解决方案

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

{

//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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值