PHP automatically arranges the test seat number, how to write a random write statement

Source: Internet
Author: User
PHP automatically arranges the test seat number, how to write a random write statement?
This is an examination of the random seating procedures, Cityid is the city ID, if from the same city, that is, the city ID of the same 3-bit location to arrange seats, to prevent cheating.

The number of students is uncertain, but there are already *

1. Student Table
UserID Cityid
001 4501
002 4502
003 4501
004 4503
005 4502
006 4502
007 4504
008 4505
009 4512
. .
. .


2. Seating chart (ZWID: Seat ID; KCID: examination room ID; Fixed 60 seat number per exam)
Zwid kcid userid Cityid
1 001
2 001
3 001
4 001
5 001
6 001
7 001
8 001
. .
. .
. .


How can you achieve the following effect (if the city ID is the same, separate the 3-bit to update the UserID and Cityid to the seating chart, you can achieve the same city without learning to be together on the line), to find

Body SQL statement, thank you!
Zwid kcid userid Cityid
1 001 003 4501
2 001 002 4502
3 001 009 4512
4 001 007 4504
5 001 001 4501
6 001 006 4502
7 001 008 4505
8 001 004 4503
9 001 005 4502
. .
. .
. .
------to solve the idea----------------------
This is an algorithmic problem.
You can iterate through the student table and insert the traversed * into the seating chart. Determine whether the first three seats have the same city before each insert before inserting the seat data; yes, no insert; no, insert.
Keep looping until the student table is all plugged in. To exclude the * that has been inserted during the loop.
  • Related Article

    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.