這是我的問題。我在mysqladmin中運行查詢,結果如預期。當我在php中運行查詢並打印到Web服務器上的表格時,我得到的列數相同,但標題之後的行中的數據混在一起。我在用PHP打印數據的方式做錯了什麼?這段代碼適用於不同的查詢,所以我很難過。當我運行相同的查詢
這是我的代碼,如果你能幫我弄清楚爲什麼我的mysqladmin結果不同於我打電話給這個php文件時打印到屏幕上的結果。
這是什麼顯示不正確。 Entry_id是一個主鍵,應始終填寫。 error http://www.sweatmansc.com/fo_claims/images/weberrorreport.PNG 這裏是中mysqladmin good http://www.sweatmansc.com/fo_claims/images/mysqladminresults.PNG
$select = "(SELECT `tbl_entry`.`entry_id`,`tbl_entry_item`.`entry_item_id`,
CASE
WHEN `tbl_entry`.`in_out_type` = 'I' THEN 'Inbound'
WHEN `tbl_entry`.`in_out_type` = 'O' THEN 'Shipped Out'
ELSE ''
END AS 'Status',
`tbl_customer`.`customer_name`,
`tbl_serv_prov`.`name` AS 'Carrier_name',
`tbl_origin_dest`.`name` AS 'Origin',
destination.`name` AS 'Destination',
`tbl_project`.`project_name`,
`tbl_component`.`component_name`,
CASE
WHEN `tbl_entry`.`truck_arrive` < '1999-01-01 00:00:00' THEN '0'
ELSE `tbl_entry`.`truck_arrive`
END AS 'truck_arrive',
CASE
WHEN `tbl_entry`.`offload_begin` < '1999-01-01 00:00:00' THEN '0'
ELSE `tbl_entry`.`offload_begin`
END AS 'offload_begin',
CASE
WHEN `tbl_entry`.`offload_end` < '1999-01-01 00:00:00' THEN '0'
ELSE `tbl_entry`.`offload_end`
END AS 'offload_end',
CASE
WHEN `tbl_entry`.`truck_left_site` < '1999-01-01 00:00:00' THEN '0'
ELSE `tbl_entry`.`truck_left_site`
END AS 'truck_left_site',
`tbl_entry`.`pro_number`,
`tbl_entry`.`checklist`,
`tbl_entry`.`truck_rail_barge`,`tbl_entry`.`bol`,
`tbl_entry`.`log_mode`,`tbl_entry_item`.`damage`,
`tbl_entry_item`.`serial_number`,`tbl_entry_item`.`dmg_desc`,
ds.`status_name` AS 'Damage_Type',`tbl_entry_item`.`fix_before_ship`,
fs.`status_name` AS 'Fix_status',`tbl_entry_item`.`mpp_defect`,
`tbl_entry_item`.`incident`,`tbl_entry_item`.`defect_avoided`,
`tbl_entry_item`.`damage_source`,`tbl_entry_item`.`defect`,
`tbl_entry_item`.`defect_comments`,`tbl_entry_item`.`incident_escalation`,
`tbl_entry_item`.`incident_injury`,`tbl_entry_item`.`incident_report_link`,
`tbl_entry_item`.`in_out_type`,`tbl_entry_item`.`incident_esc_sent`,
`tbl_entry_item`.`defect_comment`,`tbl_entry_item`.`mpp_reason`,
`tbl_entry_item`.`claim_check`,`tbl_entry_item`.`set_number`,
`tbl_entry_item`.`customer_tag`,`tbl_entry_item`.`outbound_entry_id`,
`tbl_entry_item`.`outbound_entry_item_id`,
out_tbl_entry.`entry_id`,out_tbl_entry_item.`entry_item_id`,
CASE
WHEN out_tbl_entry.`in_out_type` = 'I' THEN 'Inbound'
WHEN out_tbl_entry.`in_out_type` = 'O' THEN 'Shipped Out'
ELSE ''
END AS 'Out_Status',
'' AS 'CUSTOMER_Outbound',
out_tbl_serv_prov.`name` AS 'Outbound_Carrier_name',
out_tbl_origin_dest.`name` AS 'Origin_out',
out_destination.`name` AS 'Destination_out',
'' AS 'PROJECT_Outbound',
out_tbl_component.`component_name`,
CASE
WHEN out_tbl_entry.`truck_arrive` < '1999-01-01 00:00:00' THEN '0'
ELSE out_tbl_entry.`truck_arrive`
END AS 'out_truck_arrive',
CASE
WHEN out_tbl_entry.`offload_begin` < '1999-01-01 00:00:00' THEN '0'
ELSE out_tbl_entry.`offload_begin`
END AS 'load_begin',
CASE
WHEN out_tbl_entry.`offload_end` < '1999-01-01 00:00:00' THEN '0'
ELSE out_tbl_entry.`offload_end`
END AS 'load_end',
CASE
WHEN out_tbl_entry.`truck_left_site` < '1999-01-01 00:00:00' THEN '0'
ELSE out_tbl_entry.`truck_left_site`
END AS 'truck_left_site',
out_tbl_entry.`pro_number`,
out_tbl_entry.`checklist`,
out_tbl_entry.`truck_rail_barge`,
out_tbl_entry.`bol`,
out_tbl_entry.`log_mode`,
out_tbl_entry_item.`damage`,
out_tbl_entry_item.`serial_number`,
out_tbl_entry_item.`dmg_desc`,
out_ds.`status_name` AS 'Damage_Type',out_tbl_entry_item.`fix_before_ship`,
out_fs.`status_name` AS 'Fix_status',out_tbl_entry_item.`mpp_defect`,
out_tbl_entry_item.`incident`,out_tbl_entry_item.`defect_avoided`,
out_tbl_entry_item.`damage_source`,out_tbl_entry_item.`defect`,
out_tbl_entry_item.`defect_comments`,out_tbl_entry_item.`incident_escalation`,
out_tbl_entry_item.`incident_injury`,out_tbl_entry_item.`incident_report_link`,
out_tbl_entry_item.`in_out_type`,out_tbl_entry_item.`incident_esc_sent`,
out_tbl_entry_item.`defect_comment`,out_tbl_entry_item.`mpp_reason`,
out_tbl_entry_item.`claim_check`,out_tbl_entry_item.`set_number`,
out_tbl_entry_item.`customer_tag`,
out_tbl_entry_item.`outbound_entry_id` AS 'next_entry_link',
out_tbl_entry_item.`outbound_entry_item_id` AS 'next_entry_id_link'
FROM tbl_entry
LEFT JOIN tbl_entry_item ON `tbl_entry`.`entry_id`=`tbl_entry_item`.`entry_id`
LEFT JOIN tbl_customer ON `tbl_entry`.`customer_id`=`tbl_customer`.`customer_id`
LEFT JOIN tbl_serv_prov ON `tbl_entry`.`serv_prov_id`=`tbl_serv_prov`.`serv_prov_id`
LEFT JOIN tbl_origin_dest ON `tbl_entry`.`location`=`tbl_origin_dest`.`id`
LEFT JOIN tbl_origin_dest destination ON `tbl_entry`.`dest`= destination.`id`
LEFT JOIN tbl_project ON `tbl_entry`.`project_id`=`tbl_project`.`project_id`
LEFT JOIN tbl_component ON `tbl_entry_item`.`component_id`=`tbl_component`.`component_id`
LEFT JOIN tbl_status ds ON `tbl_entry_item`.`dmg_type`= ds.`status_id`
LEFT JOIN tbl_status fs ON `tbl_entry_item`.`fix_status`= fs.`status_id`
LEFT JOIN tbl_entry_item out_tbl_entry_item ON `tbl_entry_item`.`outbound_entry_item_id`=out_tbl_entry_item.`entry_item_id`
LEFT JOIN tbl_entry out_tbl_entry ON out_tbl_entry_item.`entry_id`= out_tbl_entry.`entry_id`
LEFT JOIN tbl_serv_prov out_tbl_serv_prov ON out_tbl_entry.`serv_prov_id`=out_tbl_serv_prov.`serv_prov_id`
LEFT JOIN tbl_origin_dest out_tbl_origin_dest ON out_tbl_entry.`location`=out_tbl_origin_dest.`id`
LEFT JOIN tbl_origin_dest out_destination ON out_tbl_entry.`dest`= out_destination.`id`
LEFT JOIN tbl_component out_tbl_component ON out_tbl_entry_item.`component_id`=out_tbl_component.`component_id`
LEFT JOIN tbl_status out_ds ON out_tbl_entry_item.`dmg_type`= ds.`status_id`
LEFT JOIN tbl_status out_fs ON out_tbl_entry_item.`fix_status`= fs.`status_id`
WHERE `tbl_entry`.`in_out_type` = 'I')
UNION
(SELECT 'No Inbound Record tied to this Outbound Record',
'See Column to right for Outbound Record','','','','',
'','','','','',
'','','','','',
'','','','','',
'','','','','',
'','','','','',
'','','','','',
'','','','','','',
`tbl_entry`.`entry_id`,`tbl_entry_item`.`entry_item_id`,
CASE
WHEN `tbl_entry`.`in_out_type` = 'I' THEN 'Inbound'
WHEN `tbl_entry`.`in_out_type` = 'O' THEN 'Outbound'
ELSE ''
END AS 'Status',
`tbl_customer`.`customer_name`,
`tbl_serv_prov`.`name` AS 'Carrier_name',
`tbl_origin_dest`.`name` AS 'Origin',
destination.`name` AS 'Destination',
`tbl_project`.`project_name`,
`tbl_component`.`component_name`,
CASE
WHEN `tbl_entry`.`truck_arrive` < '1999-01-01 00:00:00' THEN '0'
ELSE `tbl_entry`.`truck_arrive`
END AS 'truck_arrive',
CASE
WHEN `tbl_entry`.`offload_begin` < '1999-01-01 00:00:00' THEN '0'
ELSE `tbl_entry`.`offload_begin`
END AS 'offload_begin',
CASE
WHEN `tbl_entry`.`offload_end` < '1999-01-01 00:00:00' THEN '0'
ELSE `tbl_entry`.`offload_end`
END AS 'offload_end',
CASE
WHEN `tbl_entry`.`truck_left_site` < '1999-01-01 00:00:00' THEN '0'
ELSE `tbl_entry`.`truck_left_site`
END AS 'truck_left_site',
`tbl_entry`.`pro_number`,
`tbl_entry`.`checklist`,
`tbl_entry`.`truck_rail_barge`,`tbl_entry`.`bol`,
`tbl_entry`.`log_mode`,`tbl_entry_item`.`damage`,
`tbl_entry_item`.`serial_number`,`tbl_entry_item`.`dmg_desc`,
ds.`status_name` AS 'Damage_Type',`tbl_entry_item`.`fix_before_ship`,
fs.`status_name` AS 'Fix_status',`tbl_entry_item`.`mpp_defect`,
`tbl_entry_item`.`incident`,`tbl_entry_item`.`defect_avoided`,
`tbl_entry_item`.`damage_source`,`tbl_entry_item`.`defect`,
`tbl_entry_item`.`defect_comments`,`tbl_entry_item`.`incident_escalation`,
`tbl_entry_item`.`incident_injury`,`tbl_entry_item`.`incident_report_link`,
`tbl_entry_item`.`in_out_type`,`tbl_entry_item`.`incident_esc_sent`,
`tbl_entry_item`.`defect_comment`,`tbl_entry_item`.`mpp_reason`,
`tbl_entry_item`.`claim_check`,`tbl_entry_item`.`set_number`,
`tbl_entry_item`.`customer_tag`,`tbl_entry_item`.`outbound_entry_id`,
`tbl_entry_item`.`outbound_entry_item_id`
FROM tbl_entry
LEFT JOIN tbl_entry_item ON `tbl_entry`.`entry_id`=`tbl_entry_item`.`entry_id`
LEFT JOIN tbl_customer ON `tbl_entry`.`customer_id`=`tbl_customer`.`customer_id`
LEFT JOIN tbl_serv_prov ON `tbl_entry`.`serv_prov_id`=`tbl_serv_prov`.`serv_prov_id`
LEFT JOIN tbl_origin_dest ON `tbl_entry`.`location`=`tbl_origin_dest`.`id`
LEFT JOIN tbl_origin_dest destination ON `tbl_entry`.`dest`= destination.`id`
LEFT JOIN tbl_project ON `tbl_entry`.`project_id`=`tbl_project`.`project_id`
LEFT JOIN tbl_component ON `tbl_entry_item`.`component_id`=`tbl_component`.`component_id`
LEFT JOIN tbl_status ds ON `tbl_entry_item`.`dmg_type`= ds.`status_id`
LEFT JOIN tbl_status fs ON `tbl_entry_item`.`fix_status`= fs.`status_id`
WHERE `tbl_entry`.`in_out_type` = 'O' AND `tbl_entry_item`.`entry_item_id` NOT IN (SELECT outbound_entry_item_id
FROM `tbl_entry_item`
WHERE outbound_entry_item_id IS NOT NULL)
);";
$export = mysql_query ($select) or die ("Sql error : " . mysql_error());
$fields = mysql_num_fields ($export);
// datadunp
$rowIterator = 1;
//debug
echo "<table><tr>";
//header
$col = 0;
for ($i = 0; $i < $fields; $i++)
{
$header = mysql_field_name($export , $i);
//$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $rowIterator, $header);
echo "<td>";
echo $header;
echo "</td>";
$col++;
}
$rowIterator++; //end header
echo "</tr>";
//begin body
while($row = mysql_fetch_assoc($export)) {
$col = 0;
echo "<tr>";
foreach($row as $key=>$value) {
//$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $rowIterator, $value);
echo "<td>";
echo $value;
echo "</td>";
$col++;
}
$rowIterator++;
echo "</tr>";
}
echo "</table>";
共有84欄。當我減少列數似乎使查詢工作。有這麼多列是否有問題? – sweaty