Jump to content

Help in query


GOKU

Recommended Posts

I have table

 

Table for student

tb_biodata (id,nim,nama,email,....)

 

Table for company

tb_perusahaan (id_prs,nama,prs,quota)

 

Table Test

tb_test (id_test,id_siswa,id_prs)

 

Table Detail Test

tb_detail_test (id_test,id_nilai_bobot,hasil)

 

I want to display who student have highest the total of 'hasil' based on company quota (tb_perusahaan.quota)

 

php code

<?php

$sql='SELECT id_prs,nama_prs,quota FROM tb_perusahaan order by quota desc';

$qry=mysql_query($sql) or die (mysql_error());

$i=0;

while($res=mysql_fetch_row($qry)){

$i++;

echo $i.')'.$res[1].'<br>';

$sql2="select nama,nim,sum(hasil) as urut

  from tb_biodata a,tb_test b,tb_detail_test c

  where a.id=b.id_siswa

  and b.id_test=c.id_test        

  group by b.id_test

  order by urut desc limit ".$res[2];

$qry2=mysql_query($sql2) or die (mysql_error());

while($res2=mysql_fetch_row($qry2)){

echo '-'.$res2[0].' ('.$res2[1].') Total test : '.$res2[2].'<br>';

}

}

?>

 

and the result

quotaqa6.gif

 

But i have only 1 student for 1 company. In the result Martina has accepted on company a,b, and c

How can martina dispaly on only company a?

The rule is 1 company for 1 strudent. And display comnay based on quota highest to low

Anyone can help me?

Link to comment
https://forums.phpfreaks.com/topic/88166-help-in-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.