2013-01-13 16 views
-1

大家好,我想在一個循環中搜索n/a值(包括0值),並在另一個循環中用類別發送此值。我的代碼是按類別顯示mysql值中的0值,並在另一個循環中發送並扣除此值

$i=0; 
$j=0; 
$newcount=$db->get_results("SELECT s2.qcategory, s1.id, count(s1.na) as na_count FROM (select distinct `qcategory` from store) s2 left join store s1 on s1.`qcategory` = s2.`qcategory` and s1.survey_name='$userID' and s1.dateone='$dateVal' and s1.branch='$branch' and s1.`na` = '1' group by 1 order by s1.id "); 
    if($newcount) 

    foreach($newcount as $sqcount) 
    { 
    $arval[$j]=$sqcount->na_count; 
    $j++; 
    } 

$newqcat=$db->get_results("SELECT count(id) as r_count, sum(point) as point_value,dateone, na, qcategory FROM store where survey_name='$userID' and dateone='$dateVal' and branch='$branch' group by qcategory order by id"); 

if($newqcat) 
    { 
    foreach($newqcat as $sqcat1) 
      { 
     echo $sqcat1->qcategory?></a> 
     $vv1=$arval[$i]; 
     $tcount_val1=$sqcat1->r_count-$vv1; 
     $rowval=$sqcat1->qcategory; 
     $per=($sqcat1->point_value*100)/($tcount_val1*5); 
} 

} 

我要統計每個類別不象

**First impression - 3 
    Quality and value -0 
    Overall impression and ambiance - 1** 

應用價值並扣除每個N/A值在另一個循環

任何一個可以幫我該怎麼辦這個?我試過這個使用數組,但它不會正常工作

回答

1
$newqcat=$db->get_results("SELECT count(id) as r_count, sum(point) as point_value,dateone, na, qcategory FROM store where survey_name like '%$userID%' and dateone='$dateVal' and branch='$branch' group by qcategory order by id"); 
    if($newqcat) 
    { 
    foreach($newqcat as $sqcat1) 
      { 

    $newcount1=$db->get_row("SELECT s2.qcategory, s1.id, count(s1.na) as na_count FROM (select distinct `qcategory` from store where qcategory='$sqcat1->qcategory' and dateone='$dateVal' and branch='$branch') s2 left join store s1 on s1.`qcategory` = s2.`qcategory` and s1.`na` = '1' and s1.branch='$branch' and s1.dateone='$dateVal' and s1.survey_name='$userID' group by qcategory "); 








$tcount_val1=$sqcat1->r_count-$newcount1->na_count; 




    $rowval=$sqcat1->qcategory; 
    $per=($sqcat1->point_value*100)/($tcount_val1*5); 
    echo "<td align=center valign=center>".round($per)."%</td></tr>"; 








} 

} 
相關問題