In MySQL, how to draw a record every 10 lines, thank you

Source: Internet
Author: User
In MySQL, how to draw a record every 10 strips, thank you!

$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 ';
}


This will randomly draw a randomly written KS table in the member table.

How to be able to do member table inside if the CID is the same, staggered 10 random write KS table?

Or how the code should be written to achieve this purpose:
Member table has thousands of data, if the member table CID the same data staggered 10 write to the KS table, not the same random write KS table

Maybe I didn't express it very clearly, this is an examination of the random seating procedures, CID is the city ID, if the city ID is the same staggered location to arrange seats, to prevent cheating.

Thank you first, because the score is not much, to finish only 20 points, see cool!
------to solve the idea----------------------
$sql 1 = "SELECT * from ' member ' WHERE status = 0  LIMIT 1";

$cur _cid = $r 1[' cid '];//see the city where the first candidate is currently located
$sql 4 = "INSERT INTO ' ks ' (' CID ', ' userid ') VALUES ({$r 1[' cid ']},{$r 1[' CID ')})";
$db->query ($sql 4);//Insert first candidate information first

Push_next ($cur _cid);//successive recursion inserts

function Push_next ($cur _cid) {
$sql 2 = "SELECT * from ' member ' WHERE status = 0 and cid! = {$cur _cid} LIMIT 1";
$r 2 = $db->getrow ($sql 2);
$sql 3 = "INSERT INTO ' ks ' (' CID ', ' userid ') VALUES ({$r 2[' cid ']},{$r 2[' CID ')})";
$db->query ($sql 3);
Push_next ($sql 2[' CID ');
}


You can try.
------to solve the idea----------------------
First, the following questions must be identified:
1. How many candidates can be accommodated in the examination room? (That is, the number of record strips to write to the KS table at one time)
2. Participants from the student table are from several cities (select distinct CID from the members)

Identify the above two issues, you can be sure that the program will be selected in each city a few students arranged in the same examination room. For example, the examination room can accommodate 30 candidates, students from 5 different cities, then the program will be selected in each city 6 students arranged in the same examination room.

Create a two-dimensional array, the first dimension is the city ID, the second dimension is the learner ID, and a double loop to write the learner into the KS table.
I will not write the specific code, the following description of the array structure:


Candidates =
Array ("CID" = 2, "members" = = Array (2, 12, 22, 32)),
Array ("CID" = 3, "members" = = Array (3, 13, 23, 33)));


This only takes into account that the neighboring Kaoxue come from different cities, and you can expand it to add the adjacent judgments to the code logic.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.