引导可编辑 - 如何将下拉值传输到 SQL 表


bootstrap editable - how to transfer dropdown value to SQL table?

我目前正在从事一个项目,该项目使用可编辑的引导程序显示SQL表中的数据以进行实时编辑。

它工作正常 - 更改将传输到 SQL 表。什么已经起作用了?

  1. 显示 SQL 表中的当前值
  2. 提供下拉列表以供选择
  3. 将更改的值传输到 SQL 表

-> BUT 第 3 部分(传输更改的值)仅适用于自由文本输入(类 xedit)。

我正在寻找的是以下代码:将下拉列表的选定值传输到SQL表

这是 HTML 代码:

   <?php
    include("connect.php");
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta charset="utf-8">
        <link href="assets/css/bootstrap.min.css" rel="stylesheet"     type="text/css">
        <link href="assets/css/custom.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div class="container">    
    		<div style="text-align:center;width:100%;font-size:24px;margin-bottom:20px;color: #2875BB;">EDIT YOUR CHARACTERS</div>
                    <div class="row">
                        <table class= "table table-striped table-bordered table-hover">
                            <thead>
                                <tr>
                                    <th colspan="1" rowspan="1" style="width: 180px;" tabindex="0">NAME</th>
                                    <th colspan="1" rowspan="1" style="width: 220px;" tabindex="0">ROLE</th>
                                    <th colspan="1" rowspan="1" style="width: 288px;" tabindex="0">SECOND ROLE</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
    						$query = mysql_query("SELECT * FROM characters");
    						$i=0;
    						while($fetch = mysql_fetch_array($query))
    						{
    							if($i%2==0) $class = 'even'; else $class = 'odd';
    							
    							echo'<tr class="'.$class.'">
                                    <td class="xedit" id="'.$fetch['id'].'" key="name">'.$fetch['name'].'</td>
    								<td class="xedit" id="'.$fetch['id'].'" key="role">'.$fetch['role'].'</td>
    								<td class="xedit2" id="'.$fetch['id'].'" key="secondrole"><a href="#" class="rolestatus" data-type="select" data-pk="3" data-url="" data-title="Select status">'.$fetch['secondrole'].'	</a></td>
                                    </td>
    					            
                                </tr>';	
                            }
    						?>
                            </tbody>
                        </table>
            </div>
            </div>              
    		<script src="assets/js/jquery.min.js"></script> 
    		<script src="assets/js/bootstrap.min.js"></script>
            <script src="assets/js/bootstrap-editable.js" type="text/javascript"></script> 
            
            
    <script>
    $(function(){
        $('.rolestatus').editable({    
            source: [
                  {value: 1, text: 'DD'},
                  {value: 2, text: 'HEAL'},
                  {value: 3, text: 'TANK'}
               ]
        }); 
    });
    </script>
            
            
    <script type="text/javascript">
    jQuery(document).ready(function() {  
            $.fn.editable.defaults.mode = 'popup';
            $('.xedit').editable();		
    		$(document).on('click','.editable-submit',function(){
    		var key = $(this).closest('.editable-container').prev().attr('key');
    var x = $(this).closest('.editable-container').prev().attr('id');
    var y = $('.input-sm').val();
    var z = $(this).closest('.editable-container').prev().text(y);
    			$.ajax({
    				url: "process.php?id="+x+"&data="+y+'&key='+key,
    				type: 'GET',
    				success: function(s){
    					if(s == 'status'){
    					$(z).html(y);}
    					if(s == 'error') {
    					alert('Error Processing your Request!');}
    				},
    				error: function(e){
    					alert('Error Processing your Request!!');
    				}
    			});
    		});
    });
    </script>
        </div>
    </body>
    </html>

这是过程.php代码

          <?php
          include("connect.php");
          if($_GET['id'] and $_GET['data'])
          {
	      $id = $_GET['id'];
          $data = $_GET['data'];
          $key = $_GET['key'];
          if(mysql_query("update characters set $key='$data' where id='$id'"))
	      echo 'success';
          }
          ?>

那么有谁知道如何将所选的下拉值(类 -> xedit2)传输到 SQL 表?

希望你能帮到你!

不确定 x 可编辑的工作原理

但是乍一看,我认为如果你想更新一些数据,你的ajax的类型应该是"POST"。在我看来,您在"$key"附近的sql查询中存在语法错误