getAll($sql);fo">
时间:2021-07-01 10:21:17 帮助过:13人阅读
$sql="SELECT `cid` FROM `ks` where `cid`='' ORDER BY rand() LIMIT 100";
$r = $db->getAll($sql);
foreach($r as $v){
$sql="select `cid` from `member` WHERE `cid` not in (select `cid` from `ks`) ORDER BY rand() LIMIT 1";
$row = $db->getRow($sql);
$cid=$v['cid'];
$sql="update `ks` set `userid`='".$row['id']."' WHERE `cid`='$cid'";
}
$sql1 = "select * from `member` WHERE status = 0 LIMIT 1";
$r1 = $db->getRow($sql1);
$cur_cid = $r1['cid'];//查看当前第一个考生的所在城市
$sql4 = "insert into `ks` (`cid`,`userid`) values ({$r1['cid']},{$r1['cid']})";
$db->query($sql4);//先插入第一个考生信息
push_next($cur_cid);//接二连三的递推插入
function push_next($cur_cid){
$sql2 = "select * from `member` WHERE status = 0 and cid != {$cur_cid} LIMIT 1";
$r2 = $db->getRow($sql2);
$sql3 = "insert into `ks` (`cid`,`userid`) values ({$r2['cid']},{$r2['cid']})";
$db->query($sql3);
push_next($sql2['cid']);
}
candidates = array (array("cid" => 1, "members" => array(1, 11, 21, 31)),
array("cid" => 2, "members" => array(2, 12, 22, 32)),
array("cid" => 3, "members" => array(3, 13, 23, 33)));