在特定日期和时间范围内在MySQL中更新/插入随机日期的方法 [英] Ways of Updating/Inserting Random dates in MySQL within a specific date and time range

查看:732
本文介绍了在特定日期和时间范围内在MySQL中更新/插入随机日期的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何更新/插入随机SQL中指定日期范围内的日期

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

我的MySQL数据库表包含以下列:

My MySQL database Table has the following columns:

Primary_ID, Begin_Date, End_Date, Timestamp

如何使用phpmyadmin更新,在指定日期范围(例如:一个月中的30天)内具有随机生成的begin_dates和时间戳的选定行. 例如预期的结果

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

日期范围介于2008-09-01和2008-09-31之间. 时间可变24小时

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

我是新手,因此可以在phpmyadmin中使用的语法会很有帮助.

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

我们正在为500个成员的健身房站点做演示,但是添加的成员值都具有相同的开始日期和时间.尝试将它们分成数据库中不同的每月注册,例如,8月在不同的日期和时间注册了50个人,10月的注册了35个人,等等.

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.

当我在这里尝试一些答案时,出现以下错误:#1064-您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的'$ randomDate = rand(1,31)'附近使用. 因此,理想情况下,我可以通过最少的编辑将其复制并粘贴到phpmyadmin中的代码将受到赞赏.如果可能,请按顺序.要使一个完整的虚拟对象尽可能多地单击或单击两次即可理解和执行.

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.

推荐答案

我将使用基本的PHP脚本通过一个简单的MySQL调用将它们全部删除,将它们放入数组中,并通过日期随机化器"运行该数组然后,采用新阵列并按ID更新数据库.十分简单.但是,如果不能做这么简单的事情,您可能不应该为健身房做一个演示".当某人无法进行基本操作时,这给我们其余的自由职业者一个坏名声.不要试图刻薄.只是说,不要咬得太多,不能咀嚼.

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.

该死的,你真讨厌!我知道我会为此感到后悔,但这是一个更好的细分(无需为您编写).

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

使用PHP从MySQL获取数据库信息:

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
}

使用从日期随机化器"中获得的新数组更新Mysql:

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.

如果您的工作是编写PHP,但您无法做到这一点,则无论爆发如何,都需要寻找其他工作.你真是个卑鄙的人.

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.

这篇关于在特定日期和时间范围内在MySQL中更新/插入随机日期的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆