Leave the great god, slide the update and insert how to implement

Source: Internet
Author: User

Case ' Focus ': $id =$_post[' id ']; $name =$_post[' slide_name '); $img =$_post[' img ']; $href =$_post[' slide_href '; $q =count ($id); for ($i =0; $i < $q; $i + +) {$sql = "INSERT into zt_slide set Slide_name= '". $name [$i]. "', slide_img= '". $img [$i]. "', Slide_href= ' ". $href [$i]." ' On DUPLICATE KEY UPDATE slide_name = ' ". $name [$i]." ', Slide_href = ' ". $href [$i]." ', slide_img= ' ". $img [$i]." ', id= ' ". $id [$ I]. "'"; Echo $sql;


Page Map:



This page can be modified and added to the address picture of the slide to wait, the form will now pass the value to the background, the background to the value of the data from the page to form a SQL statement, the statement needs to update the title of the slide connection and other fields, and if the table does not have this slide record insert a new record, Now do this step stuck, ask the great God, online, etc.!!


Reply to discussion (solution)

But you did not specify the source, format, of the data you need to get ...

If there is no clear identification, then choose a trouble point, first delete the data, and then all the insert

But you did not specify the source, format, of the data you need to get ...
Open the page at the beginning data will be queried well put in input text inside
Upload image is used by the plugin upload successful, the address will be inserted into the corresponding input text, so the background only need to get all the input text content can be

Now that you've got it all figured out, you don't know what you're asking.


Case ' Focus ': $id =$_post[' id ']; $name =$_post[' slide_name '); $img =$_post[' img ']; $href =$_post[' slide_href '; $q =count ($id); for ($i =0; $i < $q; $i + +) {$sql = "INSERT into zt_slide set Slide_name= '". $name [$i]. "', slide_img= '". $img [$i]. "', Slide_href= ' ". $href [$i]." ' On DUPLICATE KEY UPDATE slide_name = ' ". $name [$i]." ', Slide_href = ' ". $href [$i]." ', slide_img= ' ". $img [$i]." ', id= ' ". $id [$ I]. "'"; Echo $sql;


Page Map:



This page can be modified and added to the address picture of the slide to wait, the form will now pass the value to the background, the background to the value of the data from the page to form a SQL statement, the statement needs to update the title of the slide connection and other fields, and if the table does not have this slide record insert a new record, Now do this step stuck, ask the great God, online, etc.!!

I don't know what your table structure looks like.
Guess the

Table only son the value that is passed, which is equivalent to doing an update updating the data operation (the title of the slide connection and other fields),
If there is no slide record in the table, then you first query table select * FROM table where huandengpain=?, whether there is a value,
If the value does not exist, insert into table ...

Now that you've got it all figured out, you don't know what you're asking.
Query is good, the key is to modify and add this step, the modified data and the new data passed to the background, now is the background to accept these values how to operate the database, you need to query the record, there is no change, no insert a new record, but such a SQL will not write AH

You check first.
Modify if it exists
Insert if it does not exist

You check first.
Modify if it exists
Insert if it does not exist
I want to write something like this:
INSERT into Zt_slide set Slide_name= ' ". $name [$i]." ', slide_img= ' ". $img [$i]." ', slide_href= ' ". $href [$i]." ' On DUPLICATE KEY UPDATE slide_name = ' ". $name [$i]." ', Slide_href = ' ". $href [$i]." ', slide_img= ' ". $img [$i]." ', id= ' ". $id [$ I]. "'


You check first.
Modify if it exists
Insert if it does not exist
I want to write something like this:
INSERT into Zt_slide set Slide_name= ' ". $name [$i]." ', slide_img= ' ". $img [$i]." ', slide_href= ' ". $href [$i]." ' On DUPLICATE KEY UPDATE slide_name = ' ". $name [$i]." ', Slide_href = ' ". $href [$i]." ', slide_img= ' ". $img [$i]." ', id= ' ". $id [$ I]. "'
You do not satisfy the rules of MySQL writing, or you do not have to judge the PHP program, then you directly write the stored procedure.

  • 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.