dongshuofu0039 2017-06-01 10:12
浏览 53
已采纳

如何从数组中打印特定值?

i want to print first value of id 219 is mentioned in the screenshot for case:downloadl then i need to print 2nd value id=219 for case :downloadp.but,the array $value['printp'] getting both the values into the table(ex:Select usera Select userb). but i need to print only one and first value for this $value['printp']. enter image description here

case 'downloadl':


$sql = "SELECT post_id,printprocess,printsupply,printesb,printwork,printpri,printmate FROM printtable WHERE post_id=" .$post_id;

        $query = $db->sql_query($sql);
        $print_data = array();
        while($roww = mysqli_fetch_array($query)){

                 $print_data[] = array(
                 'printp'   =>  $roww['printprocess'],
                 'prints'   =>  $roww['printsupply'],
                 'printsb'  =>  $roww['printesb'],
                 'printwrk' =>  $roww['printwork'],
                 'printpr'  =>  $roww['printpri'],
                 'printmat' =>  $roww['printmate'],
                 );
        }

              foreach($print_data as $value) {

                    $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A'.$j, '');
                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, '');
                    $j++;
                    $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A'.$j, 'Printing Process');
                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printp']);
                    $j++;
                    $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A'.$j, 'Supplier');
                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['prints']);
                    $j++;
                    $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A'.$j, 'Espon Sub');
                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printsb']);
                    $j++;
                    $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A'.$j, 'WorkFlow ID');
                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printpr']);
                    $j++;
                    $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A'.$j, 'Printer');
                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printwrk']);
                    $j++;
                    $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A'.$j, 'Printing Material');
                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printmat']);
                    $i++;
                    $j++;
                }
 break;
              case:downloadp:

            foreach($print_data as $value) {

                            $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue('A'.$j, '');
                            $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, '');
                            $j++;
                            $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue('A'.$j, 'Printing Process');
                            $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printp']);
                            $j++;
                            $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue('A'.$j, 'Supplier');
                            $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['prints']);
                            $j++;
                            $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue('A'.$j, 'Espon Sub');
                            $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printsb']);
                            $j++;
                            $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue('A'.$j, 'WorkFlow ID');
                            $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printpr']);
                            $j++;
                            $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue('A'.$j, 'Printer');
                            $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printwrk']);
                            $j++;
                            $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue('A'.$j, 'Printing Material');
                            $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printmat']);
                            $i++;
                            $j++;
                        }
       break;
  • 写回答

4条回答 默认 最新

  • doucuan5365 2017-06-01 10:42
    关注

    Change your query in the different cases.

    switch ($something) {
        case 'downloadl':
            $sql = "SELECT post_id,printprocess,printsupply,printesb,printwork,printpri,printmate FROM printtable WHERE post_id=" .$post_id . " AND printprocess = 'Select UserA'";
            break;
        case 'downloadp':
            $sql = "SELECT post_id,printprocess,printsupply,printesb,printwork,printpri,printmate FROM printtable WHERE post_id=" .$post_id . " AND printprocess = 'Select UserB'";
            break;
    }
    
    $query = $db->sql_query($sql);
    $print_data = array();
    while($roww = mysqli_fetch_array($query)){
    
        $print_data[] = array(
         'printp'   =>  $roww['printprocess'],
         'prints'   =>  $roww['printsupply'],
         'printsb'  =>  $roww['printesb'],
         'printwrk' =>  $roww['printwork'],
         'printpr'  =>  $roww['printpri'],
         'printmat' =>  $roww['printmate'],
         );
    }
    
    foreach($print_data as $value) {
    
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A'.$j, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, '');
        $j++;
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A'.$j, 'Printing Process');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printp']);
        $j++;
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A'.$j, 'Supplier');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['prints']);
        $j++;
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A'.$j, 'Espon Sub');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printsb']);
        $j++;
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A'.$j, 'WorkFlow ID');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printpr']);
        $j++;
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A'.$j, 'Printer');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printwrk']);
        $j++;
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A'.$j, 'Printing Material');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$j, $value['printmat']);
        $i++;
        $j++;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀