简体   繁体   English

当我运行相同的查询时,php mysql结果在打印表中与我在mysql admin中得到的不匹配

[英]php mysql results in printed table not matching what I get in mysql admin when I run the same query

Here is my problem. 这是我的问题。 I run a query in mysqladmin and the results are as expected. 我在mysqladmin中运行查询,结果符合预期。 When I run the query in php and print to a table on the web server I get the same number of columns, but the data in the rows after the header are mixed up. 当我在php中运行查询并打印到Web服务器上的表时,我得到了相同数量的列,但是标题后面的行中的数据混合了。 Am I doing something wrong with the way I am printing the data in PHP? 我在PHP中打印数据的方式有问题吗? This code works for a different query so I'm stumped. 这段代码适用于其他查询,因此我很困惑。

Here is my code if you can help me figure out why my mysqladmin results are different from what is printed to the screen when I call this php file. 这是我的代码,如果您可以帮助我弄清楚为什么我的mysqladmin结果与调用此php文件时在屏幕上显示的结果不同。

Here is what is not displaying correctly. 这是无法正确显示的内容。 Entry_id is a primary key and should always be filled in. error http://www.sweatmansc.com/fo_claims/images/weberrorreport.PNG Here is the same query in mysqladmin good http://www.sweatmansc.com/fo_claims/images/mysqladminresults.PNG Entry_id是一个主键,应始终填写。error http://www.sweatmansc.com/fo_claims/images/weberrorreport.PNG这是mysqladmin中的同一查询http://www.sweatmansc.com/fo_claims/图片/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>";
foreach($row as $key=>$value) {
        //$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $rowIterator, $value);
        echo "<td>";
        //echo $value;
        echo htmlspecialchars($value);
        echo "</td>";
        $col++;
    }

Maybe your query data contains some special characters which cannnot be displayed in HTML. 也许您的查询数据包含一些无法在HTML中显示的特殊字符。

If htmlspecialchars() doesn't work, you may want to try htmlentities(). 如果htmlspecialchars()不起作用,则可能要尝试htmlentities()。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我从php中的mysql查询中得到更多结果,然后再问什么呢? - Why do i get more results from my mysql query in php then what i ask for? 两个mysql查询和2个$ results。 我可以仅使用一个mysql查询获得相同的2 $ results吗? - Two mysql queries and 2 $results. Can I get the same 2 $results using only one mysql query? 使用PHP我发出一个MySQL数据库的简单查询-当在phpMyAdmin中发出相同查询时,我得到一个错误,我得到信息行 - Using PHP I issue a simple query of a MySQL database - I get an error, when issuing the same query in phpMyAdmin I get rows of information PHP代码结果与MySQL查询不匹配 - Php code results not matching mySQL query PHP中的MySQL空查询-我会得到什么? 资源ID? - Mysql empty query in php - what do I get? Resource ID? PHP和MySQL:使用$ _GET [&#39;id&#39;]查询匹配的表ID - PHP & MySQL: Using $_GET['id'] to query matching table id 如何在MySQL中运行更新查询并替换匹配的字符串 - How do I run Update Query in MySQL and replace a matching string 在PHP中以数组形式获取MySQL查询结果的最佳方法是什么? - What is the best way to get MySQL query results as an array in PHP? 当表有数据时,PHP MySQL查询返回零结果 - PHP MySQL query returning zero results when table has data 如何从同一个表中的单个 MySQL 查询中获取两组结果? - How can I fetch two sets of results in a single MySQL query from the same table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM