php+mysql Implementation of Database Random Rearrangement Instance

  • 2021-07-22 09:09:22
  • OfStack

In this paper, the method of random rearrangement of php+mysql database is implemented, which can read all the data in the table randomly once and then save it to another table randomly, thus achieving the function of random recording.

The main implementation code is as follows:

<?php
// The database connection is not written here
$s = isset( $_GET['s'] )?$_GET['s']:0;
$e = isset( $_GET['e'])?$_GET['e']:50;
$count =85000;
if( $s < $count )
{
 $sql = "select * from Table prefix _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 Table prefix _info_bak (id, Table prefix ,typeid,isget) values('$id','$sss','$typeid','$isget')";
  mysql_query( $sql ) ;
  echo $sql;
  //exit;
  $sqlu = "update Table prefix _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"> Processing data, currently '.$s.' Article...... ';
}
else
{
 echo ' Complete all data processing <a href=rand.php> Random sorting again 1 Times </a>';
}
?>

I hope this article is helpful to everyone's PHP programming.


Related articles: