Reputation: 431
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'].
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;
Upvotes: 0
Views: 112
Reputation: 781888
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++;
}
Upvotes: 1
Reputation: 5796
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
and LIMIT 1
will limit the number of rows returned to 1.
Upvotes: 1
Reputation: 180
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:
$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
foreach($print as $value)
from your code to print the first value.
Upvotes: 1
Reputation: 619
use LIMIT 1
SELECT post_id,printprocess,printsupply,printesb,printwork,printpri,printmate FROM printtable WHERE post_id=" .$post_id." LIMIT 1";
Upvotes: 1