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'].
我想打印第219号id的第一个值在屏幕快照中被提到:downloadl然后我需要打印第二个值id=219,以供case: downloadp。但是,数组$value['printp']将两个值都输入到表中(ex:选择usera选择userb)。但是我只需要打印这个$value的一个和第一个值['printp']。
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 个解决方案
#1
1
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++;
}
#2
1
use LIMIT 1
使用限制1
SELECT post_id,printprocess,printsupply,printesb,printwork,printpri,printmate FROM printtable WHERE post_id=" .$post_id." LIMIT 1";
#3
1
i think the problem is in the database,because your post_id is not an unique value,so you are pulling 2 or more values from the table. i would redesign the db, or you can use:
我认为问题在数据库中,因为您的post_id不是唯一的值,所以您从表中提取了2个或更多的值。我会重新设计数据库,或者你可以使用:
$sql = "SELECT post_id,printprocess,printsupply,printesb,printwork,printpri,printmate FROM printtable WHERE post_id=" .$post_id LIMIT 1;
to pull a single value from db, or remove the
从db中提取单个值,或删除。
foreach($print as $value)
from your code to print the first value.
从您的代码中打印第一个值。
#4
1
Use this query:
使用这个查询:
$sql = "SELECT post_id,printprocess,printsupply,printesb,printwork,printpri,printmate FROM printtable WHERE post_id=" .$post_id . " ORDER BY pid LIMIT 1";
Here ORDER BY post_id
will return you the output in increasing order (by default) of post_id
在这里,post_id的顺序将返回您的输出,以增加(默认情况下)post_id的顺序。
and LIMIT 1
will limit the number of rows returned to 1.
而LIMIT 1将限制返回到1的行数。
#1
1
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++;
}
#2
1
use LIMIT 1
使用限制1
SELECT post_id,printprocess,printsupply,printesb,printwork,printpri,printmate FROM printtable WHERE post_id=" .$post_id." LIMIT 1";
#3
1
i think the problem is in the database,because your post_id is not an unique value,so you are pulling 2 or more values from the table. i would redesign the db, or you can use:
我认为问题在数据库中,因为您的post_id不是唯一的值,所以您从表中提取了2个或更多的值。我会重新设计数据库,或者你可以使用:
$sql = "SELECT post_id,printprocess,printsupply,printesb,printwork,printpri,printmate FROM printtable WHERE post_id=" .$post_id LIMIT 1;
to pull a single value from db, or remove the
从db中提取单个值,或删除。
foreach($print as $value)
from your code to print the first value.
从您的代码中打印第一个值。
#4
1
Use this query:
使用这个查询:
$sql = "SELECT post_id,printprocess,printsupply,printesb,printwork,printpri,printmate FROM printtable WHERE post_id=" .$post_id . " ORDER BY pid LIMIT 1";
Here ORDER BY post_id
will return you the output in increasing order (by default) of post_id
在这里,post_id的顺序将返回您的输出,以增加(默认情况下)post_id的顺序。
and LIMIT 1
will limit the number of rows returned to 1.
而LIMIT 1将限制返回到1的行数。