重复写入数据库之后,同样的查询语句却查询不出结果
<?php
set_time_limit(0);
$filepath=$_GET['uploadfile'];
require_once '../conn.php';
error_reporting(E_ALL ^ E_NOTICE);
$line=0;
$shipments=0;
$i=0;
$s=0;
$f=0;
$strSqla="SELECT MAX(number) FROM `sale_orders_restock`"; //查询sale_orders_restock表id字段最大值
$querya = mysql_query($strSqla,$conn);
$resultaa= mysql_fetch_row($querya);
$maxnum=$resultaa[0];
$maxnum++;
$file = fopen($filepath,"r") or die("打开文件失败");
while (!feof($file)) {
$buffer = fgets($file);
if ($line<>0)
{
$u=explode('', trim($buffer));
if(!empty($u[0])){
$sku=$u[10];
$sql_itemcode="SELECT * FROM `sku_rule` WHERE `sku` = '$sku'";
$querya = mysql_query($sql_itemcode,$conn);
$rs= mysql_fetch_array($querya);
$jj_sku=$rs['item_code'];
$delivery_areas=$rs['delivery_areas'];
$zhanghao=$rs['account'];
$or_id=$u[0];
$or_it_id=$u[1];
$payments_date=$u[3];
$buyer_email=$u[7];
$buyer_name=mb_convert_encoding(addslashes($u[8]), 'UTF-8','utf-8, shft-jis, gbk');
$buyer_phone=mb_convert_encoding(addslashes($u[9]), 'UTF-8','utf-8, shft-jis, gbk');
$product_name=mb_convert_encoding(addslashes($u[11]), 'UTF-8','utf-8, shft-jis, gbk');
$quantity=$u[12];
$recipient_name=mb_convert_encoding(addslashes($u[16]), 'UTF-8','utf-8, shft-jis, gbk');
$ship_address1=mb_convert_encoding(addslashes($u[17]), 'UTF-8','utf-8, shft-jis, gbk');
$ship_address2=mb_convert_encoding(addslashes($u[18]), 'UTF-8','utf-8, shft-jis, gbk');
$ship_address3=mb_convert_encoding(addslashes($u[19]), 'UTF-8','utf-8, shft-jis, gbk');
$ship_city=mb_convert_encoding(addslashes($u[20]), 'UTF-8','utf-8, shft-jis, gbk');
$ship_state=mb_convert_encoding(addslashes($u[21]), 'UTF-8','utf-8, shft-jis, gbk');
$ship_postal=mb_convert_encoding(addslashes($u[22]), 'UTF-8','utf-8, shft-jis, gbk');
$ship_country=mb_convert_encoding($u[23], 'UTF-8','utf-8, shft-jis, gbk');
$cancel_order=0;
$logistics_number="";
$logistics_company="";
$strSql_item="SELECT * FROM `jperp`.`1_item_codes` WHERE `item_code`='$jj_sku'";
$query_item = mysql_query($strSql_item,$conn);
$rs=mysql_affected_rows();
$kit=0;
if($rs>1)
{
while($rs = mysql_fetch_array($query_item) ){
$or_it="";
$jj_sku=$rs['stock_id'];
$item_quantity=$rs['quantity'];
$quantity=$quantity*$item_quantity;
if($kit>0){
$or_it=$or_it_id.$kit;
}
else
{
$or_it=$or_it_id;
}
$sql_sale=" INSERT INTO `amazon_erp`.`sale_orders_restock` (`number` ,`order_id` ,`order_item_id`,`shipments` ,`payments_date` ,`buyer_email` ,`buyer_name`,`buyer_phone_number`,`sku`,`jj_sku`,`product_name`,`quantity_purchased`,`recipient_name`,`ship_address_1`,`ship_address_2`,`ship_address_3`,`ship_state`,`ship_postal_code`,`ship_country`,`account`,`ship_city`,`cancel_order`,`delivery_areas`,`logistics_number`,`logistics_company`)VALUES ('$maxnum','$or_id','$or_it', '$shipments', '$payments_date','$buyer_email', '$buyer_name','$buyer_phone','$sku' ,'$jj_sku', '$product_name', '$quantity', '$recipient_name', '$ship_address1', '$ship_address2','$ship_address3','$ship_state' , '$ship_postal', '$ship_country', '$zhanghao', '$ship_city','$cancel_order','$delivery_areas','$logistics_number','$logistics_company')";
mysql_query($sql_sale);
$myaf = mysql_affected_rows();
$kit++;
if($myaf>0)
{
echo "import $or_id Success $myaf kit_$kit";
echo "<br/>";
$s++;
}
else
{
echo "<br/><font color='#FF0000'>";
echo "import $or_id Failure $myaf kit_$kit";
echo "</font>";
echo mysql_error();
echo "<br/>";
$f++;
}
$i++;
}
}
else
{
$sql_sale=" INSERT INTO `amazon_erp`.`sale_orders_restock` (`number` ,`order_id` ,`order_item_id`,`shipments` ,`payments_date` ,`buyer_email` ,`buyer_name` ,`buyer_phone_number` ,`sku`,`jj_sku` ,`product_name` ,`quantity_purchased`,`recipient_name`,`ship_address_1`,`ship_address_2`,`ship_address_3`,`ship_state`,`ship_postal_code`,`ship_country`,`account`,`ship_city`,`cancel_order`,`delivery_areas`,`logistics_number`,`logistics_company`)VALUES ('$maxnum','$or_id','$or_it_id', '$shipments', '$payments_date','$buyer_email', '$buyer_name','$buyer_phone','$sku' ,'$jj_sku', '$product_name', '$quantity', '$recipient_name', '$ship_address1', '$ship_address2','$ship_address3','$ship_state' , '$ship_postal', '$ship_country', '$zhanghao', '$ship_city','$cancel_order','$delivery_areas','$logistics_number','$logistics_company')";
mysql_query($sql_sale);
$myaf = mysql_affected_rows();
if($myaf>0)
{
echo "import $or_id Success $myaf";
if(empty($jj_sku) or empty($delivery_areas))
{
echo "<font color='#FF0000'>";
echo "delivery_areas Or item_code is empty!!! ";
echo "</font>";
}
echo "<br/>";
$s++;
}
else
{
echo "<br/><font color='#FF0000'>";
echo "import $or_id Failure $myaf";
echo "</font>";
echo mysql_error();
echo "<br/>";
$f++;
}
$i++;
}
}
}
$line++;
}
mysql_close($conn);
//mysql_close($sql_detrde);
echo "<br/>";
echo "<br/>";
echo "<br/>Success: $s";
echo "<br/><font color='#FF0000'>";
echo "Failure: $f";
echo "</font>";
echo "<br/>Total: $i";
echo "<br/>";
echo "<br/>Possible file upload attack!\n";
echo '<script>window.open("outputcsv_warehouse_mix.php?number='.$maxnum.'","_blank");</script>';
echo '<script>window.open("output_pdf_mix.php?number='.$maxnum.'","_blank");</script>';
echo '<script>window.open("outputcsv_warehouse_mix_label.php?number='.$maxnum.'","_blank");</script>';
echo '<script>window.open("output_pdf_mix_a4.php?number='.$maxnum.'","_blank");</script>';
?>
number int(11) 否
order_id varchar(40) 否
order_item_id bigint(40) 否
shipments int(11) 否 0
payments_date varchar(50) 否
buyer_email tinytext 否
buyer_name tinytext 否
buyer_phone_number varchar(50) 否
sku varchar(50) 否
jj_sku varchar(50) 否
product_name text 否
quantity_purchased int(11) 否
recipient_name tinytext 否
ship_address_1 text 否
ship_address_2 text 否
ship_address_3 text 否
ship_state tinytext 否
ship_postal_code varchar(50) 否
ship_country varchar(50) 否
account varchar(30) 否
ship_city varchar(30) 否
cancel_order int(2) 否
delivery_areas varchar(10) 否
logistics_number varchar(20) 否
logistics_company varchar(40)
查询语句
$Sql_hkpdf = "SELECT * , group_concat(' ' , concat_ws( ' X ', `jj_sku` , `quantity_purchased` ) , if(`quantity_purchased`> 1, '****' , ' ') ),group_concat(' ' , `order_id` , ' ') FROM ( select * from `sale_orders_restock` order by `jj_sku`) T WHERE `number` =$id AND 1=(select count(*) from `sale_orders_restock` where `recipient_name`=T.`recipient_name`) AND `quantity_purchased`=1 AND `delivery_areas` = 'HKS' GROUP BY `recipient_name` , `ship_address_1` ORDER BY length(group_concat( ' ' , concat_ws( ' X ', `jj_sku` , `quantity_purchased` ) , ' ' )) DESC,`jj_sku`";
$Result = mysql_query($Sql_hkpdf);