i have these 3 tables represent performance in various subjects 3 cat series:
cat1 adm_no eng mat bio che phy 1111 90 87 89 74 92 2222 65 87 54 65 87 3333 96 95 98 58 56 4444 58 28 88 74 85 cat2 adm_no eng mat bio che phy 1111 40 82 81 79 90 2222 67 88 78 67 84 3333 97 99 95 24 78 4444 82 22 83 76 90 cat3 adm_no eng mat bio che phy 1111 80 45 86 74 96 2222 95 87 56 65 83 3333 46 97 84 58 87 4444 78 23 80 74 83
i'd performance trend in subjects every student. instance, if i'd wish performance trend eng, result be this:
adm_no cat1 cat2 cat3 1111 90 40 80 2222 65 67 95 3333 96 97 46 4444 58 82 78
how able achieve using mysql , php? secondly , important, how achievable in case number of tables not static? (it 2 or four).
im assuming have atleast cat1. query scaisedge provided on answer. however, give idea how dynamically generate php. below function build query can use desired result.
function buildquery($subject) { $select .= "select `cat1`.adm_no, `cat1`.`$subject` cat1"; $from = ' cat1'; $i = 2; while (mysql_num_rows(mysql_query("show tables 'cat$i'"))) { $table = "cat$i"; $label = "cat$i"; $previoustable = 'cat'.($i-1); $select .= ", `$table`.`$subject` $label"; $from .= " inner join $table on `$table`.adm_no = `$previoustable`.adm_no "; $i++; } return $select.$from; }
Comments
Post a Comment