一段按顺序更新创建日期的代码

在一个时间段内随机产生一组时间,然后排序,然后逐一安排给数据库表中的每一项。
$pdodb = $db->prepare('SELECT * FROM `beiyuan`');
$pdodb->execute();
$rows = $pdodb->fetchAll(PDO::FETCH_ASSOC);
$xtime=array();
foreach($rows as $row){
array_push($xtime,mt_rand(1320422400,time()));
}
sort($xtime);
die(var_dump($xtime));
foreach($rows as $rown=> $row){
$pdodb = $db->prepare('UPDATE `beiyuan` SET `hash`=:newhash, `ctime`=:ctime WHERE `title`=:title');
$pdodb->execute(array(
':newhash'=>hash("ripemd128",$xtime[$rown]),
':ctime'=>date("Y-m-d H:i:s",$xtime[$rown]),
':title'=>$row['title']
));
}
die();

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

w

Connecting to %s