sql - Shortening a repetitive 1400-line MySQL UNION query using PHP -


I have a MYSQL table that is 1275 fields wide. Each row in the table represents a single class of students, in which 17 students per student, 75 students from X per class, hence 17 x 75 = 1275 fields.

I have prepared a SQL Union query that successfully pulls students into another table, in a row with a student.

Now, I want to use this UNION query as part of a PHP program. This is because I have "Import" queries in PHP. But, is there no way to use PHP to shorten the SQL query? Shameless, here is my code:

  $ sql = "$ t_mem2 select localcourse, statecourse, coursetitle, semester, section, teachercode, teachername, meetingcode, classpop, student_id_01, as the form of student_id In sex form sex_01, as dob_01 birth date, grade_01 grade, ethnic_01 as ethnic, last_name_01 as last_name, first_name_01 as first_name, $ c_sch $ t_mem1 unions selection localcourse, statecourse, coursetitle AS student_ID, sex_02 as sch_code from semester, section, teachercode, teacername, meetingcode, classpop, student_id_02 , Dob_02 AS DOB, Grade_02 AS grade, ethnic ethnic ASP, last_nzd2s lastname, first_name_02 first_name, $ c_sch $ t_mem1 unions select localcourse, statecourse, coursetitle & lt as sch_code as ... ...................... ..... & gt; Teachername, meetingcode, classpop, student_id_75 student_id, sex_75 as sex, dob_75 date of birth In the form of grade_75 grade, ethnic_75 as ethnic, as last_name, first_name_75 as first_name, $ c_sch $ t_mem1 order from sch_code localcourse, statecourse, semester, last_name_75 Section, teacername, meetingcode, last_name, first_name ";  

After

First of all, this query indicates that your database schema is very poor, very poor

That is why on one side, yes, you can shorten the query with PHP :.

  $ query = "$ t_mem2"; {If ($ i> 1) for ($ i & lt; = 75; $ i = 1 $ i ++) {$ Query = 'union';} $ s = "$ i", ($ if i & lt; 10) {$ s = '0'. $ S;} $ query = "Local Course, Statsauce, Curset, Semester, Select Selection ion, teachercode, teachername, meetingcode, classpop, student_id _ {$ s} as student_id, sex _ {$ s} as sex, date of birth _ {$ S} as the date of birth, grade _ {$ s} as grade, ethnic _ {$ s} as ethnic, Last_name _ {$ s} AS LastName, first_name _ {$ s} before_name, $ C_sch AS sch_code $ t_mem1 "; } $ Query "Local Curriculum, Territory, Semester, Section, Sekharnamam, MeetingCode, Last_Name, First_name" ORDER ";  

This will" shorten the query "in PHP code if, On the other hand, if you are looking to create a query , this database reduces , it is also possible; just, $ query To start and modify all the results loop above for glom together in an array. We will finish with 75 questions made by the team, and PHP will perform UNION.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -