php jquery,拖拽保存到mysql数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/830336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:00:06  来源:igfitidea点击:

Jquery, drag and drop and save to mysql database?

phpjquerymysqldrag-and-drop

提问by djn

I have been searching all over the web, i could only found the inettuts-with-cookies, which teach how to use Jquery to perform drag and drop and then save in cookies. Can anyone please show me how to save to database (php and mysql)? I need it badly..

我一直在网上搜索,我只能找到 inettuts-with-cookies,它教如何使用 Jquery 执行拖放然后保存在 cookie 中。谁能告诉我如何保存到数据库(php 和 mysql)?我非常需要它..

EDIT:

编辑:

First, I am not php beginner, but a AJAX beginner. Those tutorials are only for 1 column. Does any one have drag and drop and save to database for 2 or 3 columns? PLEASE>>>

首先,我不是php初学者,而是AJAX初学者。这些教程仅适用于 1 列。有没有人拖放并保存到数据库中的 2 或 3 列?请>>>

回答by Mike Robinson

This is pretty broad. My first reaction is: go read a PHP beginners book. That being said, you'll need to learn the following:

这是相当广泛的。我的第一反应是:去看一本PHP初学者的书。话虽如此,您需要学习以下内容:

Then try reading these comprehensive tutorials:

然后尝试阅读这些综合教程:

Update:Sounds like you should send your data with JSON, which follows a structure similiar to XML. Your best bet is to start at JSON.org. There's also tutorials on the jQuery site regarding their JSON functions for GET and POST.

更新:听起来您应该使用 JSON 发送数据,其遵循类似于 XML 的结构。最好的办法是从JSON.org开始。jQuery 站点上还有关于 GET 和 POST JSON 函数的教程。

As for updating multiple columns, you can either do multiple AJAX posts, or use PHP to split apart the passed data and hit the DB multiple times. That's my best guess, based on the info you've posted.

至于更新多列,你可以做多个 AJAX 帖子,或者使用 PHP 将传递的数据拆分并多次命中数据库。根据您发布的信息,这是我最好的猜测。

回答by Tony

Here are a few links to help you with drag and drop: http://geekswithblogs.net/AzamSharp/archive/2008/02/21/119882.aspxhttp://www.codeproject.com/KB/webforms/JQueryPersistantDragDrop.aspxIt's really easy but you have to write the code based on your specific application.

这里有一些链接可以帮助您进行拖放:http: //geekswithblogs.net/AzamSharp/archive/2008/02/21/119882.aspx http://www.codeproject.com/KB/webforms/JQueryPersistantDragDrop。 aspx这真的很简单,但您必须根据您的特定应用程序编写代码。

In the onDrop method, you need to write an Ajax request to POST the data you want to save. The JQuery AJAX API is here: http://docs.jquery.com/Ajax/jQuery.post#urldatacallbacktype

在onDrop方法中,你需要写一个Ajax请求来POST你要保存的数据。JQuery AJAX API 在这里:http: //docs.jquery.com/Ajax/jQuery.post#urldatacallbacktype

The POST URL should refer to the PHP script which will save the data. On the PHP side, you connect to the DB:

POST URL 应引用将保存数据的 PHP 脚本。在 PHP 端,您连接到数据库:

<?php 
        $dbc = mysql_connect('localhost:/private/tmp/mysql.sock', 'root', 'password') or die (mysql_error());   
        mysql_select_db('database_name');
?>

Then you write an INSERT statement. This is an insert statement for music shows:

然后你写一个 INSERT 语句。这是音乐节目的插入语句:

$sql_insert = "INSERT INTO shows (date,venue,venueLink,location,comment,time,dateOrder,locComment,confirm_by) VALUES ('".$Date."', '".$Venue."', '".$VenueLink."', '".$Location."', '".$Comment."', '".$Time."', '".$dateSort."', '".$locComment."', '".$confirmAll."')";

$Venue, for example, would be a variable in your AJAX post request. You can get these variables from PHP superglobals:

例如,$Venue 将是您的 AJAX 发布请求中的一个变量。您可以从 PHP 超全局变量中获取这些变量:

$Venue = $_POST['venue']

FYI: You can make that query look much better because double quotes actually print variables...I just copied and pasted some noob code I found from a while back. You can worry about making it pretty later.

仅供参考:您可以使该查询看起来更好,因为双引号实际上会打印变量......我只是复制并粘贴了一些我从前一段时间发现的菜鸟代码。你可以担心以后做得很好。