php+mysql實現數據庫隨機重排實例
更新時間:2014年10月17日 09:48:23 投稿:shichen2014
這篇文章主要介紹了php+mysql實現數據庫隨機重排,講述了MySQL的查找及更新等處理技巧,有一定的參考借鑒價值,需要的朋友可以參考下
本文實例實現了php+mysql數據庫隨機重排的方法,可將表中的所有數據隨機讀出來一次之后再進行隨機保存到另一個表,從而達到了記錄隨機的功能。
主要實現代碼如下:
復制代碼 代碼如下:
<?php
//數據庫連接就不寫在這里面了
$s = isset( $_GET['s'] )?$_GET['s']:0;
$e = isset( $_GET['e'])?$_GET['e']:50;
$count =85000;
if( $s < $count )
{
$sql = "select * from 表前綴_info where isget =0 order by id desc limit $s,$e ";
$query = mysql_query( $sql );
while( $rs = mysql_fetch_array( $query ) )
{
$id = $rs['id'];
$sss = $rs['sss'];
$typeid = $rs['typeid'];
$isget = $rs['isget'];
$sql = "insert into 表前綴_info_bak (id,表前綴,typeid,isget) values('$id','$sss','$typeid','$isget')";
mysql_query( $sql ) ;
echo $sql;
//exit;
$sqlu = "update 表前綴_info set isget=1 where id =".$rs['id'];
mysql_query( $sqlu );
}
echo '<meta http-equiv="refresh" content="0;url=rand.php?s='.($s+50).'&e=50">正在處理數據,當前為'.$s.'條......';
}
else
{
echo '完成所有數據處理 <a href=rand.php>再隨機排序一次</a>';
}
?>
//數據庫連接就不寫在這里面了
$s = isset( $_GET['s'] )?$_GET['s']:0;
$e = isset( $_GET['e'])?$_GET['e']:50;
$count =85000;
if( $s < $count )
{
$sql = "select * from 表前綴_info where isget =0 order by id desc limit $s,$e ";
$query = mysql_query( $sql );
while( $rs = mysql_fetch_array( $query ) )
{
$id = $rs['id'];
$sss = $rs['sss'];
$typeid = $rs['typeid'];
$isget = $rs['isget'];
$sql = "insert into 表前綴_info_bak (id,表前綴,typeid,isget) values('$id','$sss','$typeid','$isget')";
mysql_query( $sql ) ;
echo $sql;
//exit;
$sqlu = "update 表前綴_info set isget=1 where id =".$rs['id'];
mysql_query( $sqlu );
}
echo '<meta http-equiv="refresh" content="0;url=rand.php?s='.($s+50).'&e=50">正在處理數據,當前為'.$s.'條......';
}
else
{
echo '完成所有數據處理 <a href=rand.php>再隨機排序一次</a>';
}
?>
希望本文所述對大家的PHP程序設計有所幫助。
相關文章
PHP Class&Object -- 解析PHP實現二叉樹
本篇文章是對PHP中二叉樹的實現代碼進行詳細的分析介紹,需要的朋友參考下2013-06-06

