How to Generate a Report Card for Students from This Three Table with Mysql and Php -


i have 3 tables link together. want generate report card students in class.

table students_info

name      sex age students_id --------- --- --- ----------- kinsley   m    12           1 michael   m    12           2 rhianna   f    22           3 

table scores_panel

1stca 2ndca exam students_id subjectid ----- ----- ---- ----------- ---------    23    15   42           1         1    10    12    7           1         2    43    15   62           1         3    10    12   27           2         1    10    12   57           2         2    23    15   12           2         3    11    12   27           3         1    04    12   57           3         2    13    25   12           3         3 

table subject

subjectname subjectid ----------- --------- english             1 maths               2 biology             3 

i want result this:

name kinsley sex m age 12 

and report card follow

subject   1stca 2ndca exam --------- ----- ----- ---- english      23    15   42 maths        10    12    7 biology      43    15   62 

... , on students

only 1 subject , scores retrieved instead of

<?php include("connect.php");  $generate="select students_info.name, subject.subjectname, scores_panel.1stca, scores_panel.2ndca, scores_panel.exam students_info left join scores_panel on students_info.students_id=scores_panel.students_id left join subject on subject.subjectid=scores_panel.subjectid group scores_panel.subjectid  ";  $fetch=mysql_query($generate); while($row=mysql_fetch_array($fetch)or die(mysql_error())) { ?> **name:**  <?php echo $row['name']; ?> subject 1stca 2ndca exam ---------- <?php echo $row['subjectname']; ?> <?php echo $row['1stca']; ?>      <?php echo $row['2ndca']; ?>    <?php echo $row['exam']; ?>  report card  <?php } ?> 

it works, displays 1 subject each student,

example

  name rhianna      sex f     age 22 

and report card follow

subject   1stca 2ndca exam --------- ----- ----- ---- english      11    12   27 

name kinsley sex m age 12

and report card follow

subject   1stca 2ndca exam --------- ----- ----- ---- english      23    15   42 

instead of this:

  name kinsley     sex m     age 12 

and report card follow

subject   1stca 2ndca exam --------- ----- ----- ---- english      23    15   42 maths        10    12    7 biology      43    15   62     name rhianna      sex f     age 22 

and report card follow

subject   1stca 2ndca exam --------- ----- ----- ---- english      11    12   27 maths        04    12    57 biology      13    25   12 

... , on students.

your e appreciate

thanks

you close. missed students_info.students_id in group claues

select students_info.name, subject.subjectname, scores_panel.1stca, scores_panel.2ndca, scores_panel.exam students_info left join scores_panel on students_info.students_id=scores_panel.students_id left join subject on subject.subjectid=scores_panel.subjectid group students_info.students_id,scores_panel.subjectid 

fiddle


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -