Jump to content

php mysql code issue with distinct count


pvincent

Recommended Posts

hi

 

Please find the code to display data from table, attached is the image of

displayed by the below code and what is actual data is expected

 

not sure where the error is in the code

 

checked the mysql statement on mysql bench they display the correct data as indiviudal codes

 

need help to fix the issue

 

                        <?php
   $test_operation=array();
   $total1=array();
   $build=array();
   $pro_name1=array();
   $mfg_site=array();
   $total_proto=array();
   $built_total_qtys=array();
   $assembly_part_no=array();
   $build_qty=array();
   $build_pro=array();
  $pro=explode(",",$_SESSION['pro_name1']);
   $npibuild=mysql_query("select project_name,count(distinct serial_no) as count from raw_yield_data where project_name ='".$_GET['pr_name']."' and  build like 'P%' group by project_name order by serial_no ");
   while($row=mysql_fetch_array($npibuild))
   {       
   $built_total_qtys[]=$row['count'];
   $pro_name1[]=$row['project_name'];
   }   
   $test_type=array();
   $buldtype=mysql_query("select build, assembly_part_no, count(distinct serial_no)as b, project_name, mfg_site from raw_yield_data where project_name ='".$_GET['pr_name']."' and build like 'P%' group by build, assembly_part_no");
   $total_count_value=array();
  while($row=mysql_fetch_assoc($buldtype))
  {
    $count1=0;
    $sum=0;
    $build[]=$row['build'];
    $build_pro[$row['project_name']][]=$row['build'];
   //$pro_name[]=$row['project_name'];
    $mfg_site[]=$row['mfg_site'];
    $assembly_part_no[]=$row['assembly_part_no'];
    $build_qty[]=$row['b'];
    $sql=mysql_query("SELECT test_operation,count(test_operation)as count FROM raw_yield_data where project_name ='".$_GET['pr_name']."' and build like 'P%' and build='".$row['build']."' and build!='' AND test_operation!='' and first_pass='0' group by test_operation ");
     while($row1=mysql_fetch_assoc($sql))
    {      
       $test_type[]=$row1['test_operation'];
       $test_operation[$row1['test_operation']][$row['build']]=$row1[count];
       $sum+=$row1[count];
    }      
    $total_count_value[]=$sum;
  }  
    $data=array_unique($test_type);
      ?>    
                <thead>
                    <tr>
                        <th class="center1">Project</th>
                        <th class="center1">CM</th>
                        <th class="center1">Total Build Qty</th>
                        <th class="center1">JPN</th>
                        <th class="center1">Build</th>
                        <th class="center1">Build Qty</th>
                        <?php foreach($data as $value)
                        {                            ?>
                        <th class="center1"><?php echo $value;?></th>
                        <?php } ?>
                    </tr>
                </thead>
                <tbody>
<?php  $built_total_qty=array_reverse($built_total_qtys); $pro_name=array_reverse($pro_name1); for($j=0;$j<count($pro_name);$j++){
    $c1=0;
    for($i=0;$i<count($build_pro[$pro_name[$j]]);$i++) {  ?>
  <tr>
<?php if($c1++==0) { ?>
  <td class="center1" ><?php echo $pro_name[$j]; ?></td>
  <td class="center1"><?php echo $mfg_site[$j]; ?></td>
<td> <?php echo $built_total_qty[$j];?></td><?php } else{
?>
 <td class="center1" ></td>
 <td class="center1"></td>
 <td> </td>
<?php    
} ?>
<td class="center1"style="color: black;"><?php echo $assembly_part_no[$j]; ?></td>
   <td><a href="defect_data.php?pro_name=<?php echo $pro_name[$j];?>"><?php  echo $build_pro[$pro_name[$j]][$i];?></a></td>
   <td><?php $sql=mysql_query("select build, project_name, assembly_part_no, count(distinct serial_no) as count from raw_yield_data where project_name ='".$_GET['pr_name']."' and build!='P%' and build='" .$build_pro[$pro_name[$j]][$i]."' and build!=''  group by build, assembly_part_no");$row=mysql_fetch_array($sql); echo $row['count'];?></a></td>
   <?php foreach($data as $value) {  ?>
  <td><?php if($test_operation[$value][$build_pro[$pro_name[$j]][$i]]) echo $test_operation[$value][$build_pro[$pro_name[$j]][$i]]; else echo '0'; ?></td> <?php } ?>
  </tr>
<?php      $count1++;  }} }?>  
</tbody>
 </table>
</div>
</div>

post-179649-0-15130300-1441472544_thumb.png

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.