After the database is repeatedly written, the same query statement does not query the results

Source: Internet
Author: User
 0) {$u =explode (", Trim ($buffer)), if (!empty ($u [0])) {$sku = $u [ten]; $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 [one]), ' UTF-8 ', ' Utf-8, Shft-jis, GBK '); $ Quantity= $u [n]; $recipient _name=mb_convert_encoding (Addslashes ($u [+]), ' UTF-8 ', ' Utf-8, Shft-jis, GBK '); $ship _ Address1=mb_convert_encoding (Addslashes ($u [+]), ' UTF-8 ', ' Utf-8, Shft-jis, GBK '); $ship _address2=mb_convert_ Encoding (Addslashes ($u [+]), ' 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 []), ' UTF-8 ', ' Utf-8, Shft-jis, GBK '), $ship _state=mb_convert_encoding (Addslashes ($u [+]), ' UTF-8 ', ' Utf-8, Shft-jis, GBK '), $ship _postal=mb_convert_encoding (Addslashes ($u []), ' UTF-8 ', ' Utf-8, Shft-jis, GBK '); $ship _country=mb_convert_encoding ($u [], ' 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 "
"; $s + +;} else{echo "
"; echo "Import $or _id Failure $myaf kit_$kit"; echo ""; Echo Mysql_error (); echo "
"; $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 ""; echo "Delivery_areas Or item_code is empty!!!"; echo "";} echo "
"; $s + +;} else{echo "
"; echo "Import $or _id Failure $myaf"; echo ""; Echo Mysql_error (); echo "
"; $f + +; } $i + +;}} } $line + +; } mysql_close ($conn); Mysql_close ($sql _detrde), echo "
"; Echo"
"; Echo"
Success: $s "; echo"
"Echo" Failure: $f "; echo" "; echo"
Total: $i "; echo"
"; Echo"
Possible file Upload attack!\n "; echo"; Echo '; Echo '; Echo '; ?>


Table structure
ID Int (11) No
number int (11) No
order_id varchar (40) No
order_item_id bigint (40) No
Shipments Int (11) No 0
Payments_date varchar (50) No
Buyer_email Tinytext No
Buyer_name Tinytext No
Buyer_phone_number varchar (50) No
SKU varchar (50) No
Jj_sku varchar (50) No
Product_Name Text No
quantity_purchased Int (11) No
Recipient_name Tinytext No
Ship_address_1 Text No
Ship_address_2 Text No
Ship_address_3 Text No
Ship_state Tinytext No
Ship_postal_code varchar (50) No
Ship_country varchar (50) No
Account varchar (30) No
ship_city varchar (30) No
Cancel_order Int (2) No
Delivery_areas varchar (10) No
Logistics_number varchar (20) No
Logistics_company varchar (40)

Query statements
$SQL _hkpdf = "SELECT *, Group_concat ('  , Concat_ws (' X ', ' jj_sku ', ' quantity_purchased '), if (' Quantity_purchas Ed ' > 1, ' * * * ', '  ), Group_concat ('  , ' order_id ', '  ) from (SELECT * from ' Sale_orders_restock ' ord Er by ' jj_sku ') T WHERE ' number ' = $id and 1= (select COUNT (*) from ' sale_orders_restock ' WHERE ' recipient_name ' =t. ' Recipien  T_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);


After the first write data, query no problem, can query the relevant data, one but the second write duplicate data, the same query statement will not query the results, are null values, please question what is the reason?


Reply to discussion (solution)

1 = (select COUNT (*) from ' sale_orders_restock ' where ' recipient_name ' =t. ' Recipient_name '
Can you guarantee that Recipient_name is the only one?

Recipient_name This is not the only, there is no unique field, I added an ID field behind

I just need to import duplicate data frequently, just like that.

Since it is not unique, then 1= (select COUNT (*) from ' sale_orders_restock ' where ' recipient_name ' =t. ' Recipient_name ') when can it be set up?
Of course only when the value of Recipient_name only one time, otherwise it is 2, 3, 4 ...

' Number ' = $id and 1= (select COUNT (*) from ' Sale_orders_restock '
Here is a number, similar to the batch, each import is not the same, the first import number=1, the second time will be = 2, in each batch of cases into the summary

Number does not function to select COUNT (*) from inside

Xuzuning big, how to write it?

1 = (select COUNT (*) from ' sale_orders_restock ' where ' recipient_name ' =t. ' Recipient_name ' and ' number ' = $id) so??

Select COUNT (*) from ' sale_orders_restock ' where ' recipient_name ' =t. ' Recipient_name ' and ' number ' = $id
The meaning is: the statistical table Sale_orders_restock meet Recipient_name ' =t. ' Recipient_name ' and ' number ' = $id record count for this condition
When inserted repeatedly, the number of records may be greater than 1
So 1= (SELECT ... It won't be set up.

More than 1, the statement is long enough, the index is better, otherwise the data volume is large, there may be slow query

Ask Xuzuning greatly, how should I change the sentence to satisfy my need??

Problem solved, xuzuning greatly help me to see, this should be OK

SELECT *, Group_concat (', Concat_ws (' X ', ' jj_sku ', ' quantity_purchased '), if (' quantity_purchased ' > 1, ' * * * ') , '), Group_concat (', ' order_id ', ') from (SELECT * from ' sale_orders ' where ' number ' = $id order BY ' SKU ') T WHE RE ' number ' = $id and 1= (select COUNT (*) from ' sale_orders ' where ' number ' = $id and ' recipient_name ' =t. ' Recipient_name ') an D ' quantity_purchased ' =1 and ' delivery_areas ' = ' JPS ' GROUP by ' recipient_name ', ' ship_address_1 ' ORDER by Length (group_c Oncat (', Concat_ws (' X ', ' jj_sku ', ' quantity_purchased '), ') DESC, ' Jj_sku '

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.