How to update and insert slides

Source: Internet
Author: User
How to update and insert slides
Script $ (document ). ready (function () {$ ("# insert "). bind ("click", zj); function zj () {$ ("# insert_zt "). after ("name
Upload images'>
Article address
") ;}}); Script

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 chart:



This page can be modified and the address image of the new slide is waiting. now the form transfers the value to the background. after obtaining the value in the background, an SQL statement is formed based on the data sent from the page, the statement needs to update fields such as the title connection of the slide. if this slide record does not exist in the table, a new record is inserted. now, this step is stuck. thank you for your advice !!!


Reply to discussion (solution)

However, you did not specify the source and format of the data you want to obtain...

If there is no clearly distinguished identifier, select a troublesome one. first delete the relevant data and then re-insert all the data.

However, you did not specify the source and format of the data you want to obtain...
Data on the page will be queried at the beginning and stored in the input text.
After the uploaded image is uploaded successfully using the plug-in, the corresponding input text will be inserted to the address, so you only need to get all the input text content in the background.

Now that you have all the queries, you don't know what you want to ask.

Script $ (document ). ready (function () {$ ("# insert "). bind ("click", zj); function zj () {$ ("# insert_zt "). after ("name
Upload images'>
Article address
") ;}}); Script

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 chart:



This page can be modified and the address image of the new slide is waiting. now the form transfers the value to the background. after obtaining the value in the background, an SQL statement is formed based on the data sent from the page, the statement needs to update fields such as the title connection of the slide. if this slide record does not exist in the table, a new record is inserted. now, this step is stuck. thank you for your advice !!!

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

The value passed in the form is equivalent to an update data operation (the title connection and other fields of the slide ),
If there is no slide record in the table, first query the table select * from table where huandengpain = ?, Existence value,
If the value does not exist, insert into table ......

Now that you have all the queries, you don't know what you want to ask.
Query is a good query. The key is to modify and add the data. the modified data and the new data are transmitted to the backend. now, how does the backend receive these values to operate the database, you need to first query whether this record exists and modify it. if there is no record, a new record will be inserted, but such an SQL statement will not be written.

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

You first query
Modify it 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 first query
Modify it 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]. "'
Writing in this way does not meet the mysql writing rules, or you do not need to judge by 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.