mysql で 10 レコードごとに 1 レコードを抽出するにはどうすればよいですか?
<br />$sql="SELECT `cid` FROM `ks` where `cid`='' ORDER BY rand() LIMIT 100";<br />$r = $db->getAll($sql); <br />foreach($r as $v){<br />$sql="select `cid` from `member` WHERE `cid` not in (select `cid` from `ks`) ORDER BY rand() LIMIT 1";<br />$row = $db->getRow($sql);<br />$cid=$v['cid'];<br />$sql="update `ks` set `userid`='".$row['id']."' WHERE `cid`='$cid'"; <br />}<br />
$sql1 = "select * from `member` WHERE status = 0 LIMIT 1";<br />$r1 = $db->getRow($sql1); <br />$cur_cid = $r1['cid'];//查看当前第一个考生的所在城市<br />$sql4 = "insert into `ks` (`cid`,`userid`) values ({$r1['cid']},{$r1['cid']})";<br />$db->query($sql4);//先插入第一个考生信息<br /><br />push_next($cur_cid);//接二连三的递推插入<br /><br />function push_next($cur_cid){<br /> $sql2 = "select * from `member` WHERE status = 0 and cid != {$cur_cid} LIMIT 1";<br /> $r2 = $db->getRow($sql2);<br /> $sql3 = "insert into `ks` (`cid`,`userid`) values ({$r2['cid']},{$r2['cid']})";<br /> $db->query($sql3);<br /> push_next($sql2['cid']);<br />}
<br />candidates = array (array("cid" => 1, "members" => array(1, 11, 21, 31)), <br /> array("cid" => 2, "members" => array(2, 12, 22, 32)),<br /> array("cid" => 3, "members" => array(3, 13, 23, 33)));<br />