hi guys..i really need your help to solve my dummy problem coz i'm new in sql and php..actually i have 2 queries statements.. the 1st one will produce id_iklan based on some criterias entered.. so the 2nd query will find the sum of hit_final, using the id_iklan in the previous query. the problem is that, the 1st query produce thousands of data which each of data will be used in the 2nd query. the 2nd query also produce thousands of data.. so what i did will used a lot of time and some will be ignored by server.. the codes are as follow :
$cari_lot=mysql_query("SELECT * FROM lot a, iklan b WHERE a.id_team='$id_team' and a.active_date<='$sdb' and a.active_date<'$today' and a.expiry_date>'$sdb' and a.expiry_date>'$today' AND a.id_iklan=b.id_ads");
while ($res3=mysql_fetch_array($cari_lot)){
$hit_final=0;
$id_iklan=$res3['id_ads'];
$id_lot=$res3['id_lot'];
$hit=$res3['hit'];
$id_member=$res3['id_member'];
$cari_payment=mysql_query("SELECT * FROM payment WHERE id_ad='$id_iklan'");
if(mysql_num_rows($cari_payment)){
while($res4=mysql_fetch_array($cari_payment)){
$hit_final+=$res4['hit_final'];
}


