GOKU Posted January 28, 2008 Share Posted January 28, 2008 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 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? Quote Link to comment https://forums.phpfreaks.com/topic/88166-help-in-query/ Share on other sites More sharing options...
fenway Posted January 28, 2008 Share Posted January 28, 2008 Please re-phrase your question. Quote Link to comment https://forums.phpfreaks.com/topic/88166-help-in-query/#findComment-451436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.