2017-06-24 30 views
0

我在一个真正的捏......我的任务是使这个网站上的数据表可编辑。基本上,每一行都需要有一个编辑和删除选项。问题在于我的数据表是通过我的数据库表填充的,所以如果进行了任何编辑或删除了任何行,它将需要通过更新或删除来影响数据库。编辑/删除wordpress站点中的数据表行

我对这些表有些问题在这个特定的wordpress网站上,主要涉及列的可视性和按钮,但是,我真的有压力让我明天有这个工作,并且我不知所措,

我见过Editor插件在datatables.net但我很混乱d以及如何在本网站中使用它。要记住的主要事情是这是一个WordPress的网站,我的表格充满并受phpMyAdmin中控制的数据库影响。

我是这方面的新手,所以任何能解决问题的解决方案都令人难以置信。

我的数据库连接和查询:

$server = "localhost"; 
$user = "user"; 
$pw = "password" 
$db = "database"; 

$connect = mysqli_connect($server, $user, $pw, $db); 



if ($connect->connect_error) { 
die("Connection failed: " . $conn->connect_error); 
}else{ 
    //echo'success!'; 
} 

$query1 = "SELECT * FROM staging;"; 
$result1 = mysqli_query($connect,$query1); 
$query2 = "SELECT * FROM stagingSurvey;"; 
$result2 = mysqli_query($connect,$query2); 
?> 

我的用于与所述数据表代码包括和CSS:

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css" /> 
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.3.1/css/buttons.dataTables.min.css" /> 
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.3.1/js/dataTables.buttons.min.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.colVis.min.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.flash.min.js"></script> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script> 
<script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/pdfmake.min.js"></script> 
<script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/vfs_fonts.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.html5.min.js"></script> 

</head> 
<body style="background-color:#3A6587";> 

<label style="font-weight:bold;">Select the table you would like to view:</label></br> 
<select name='tables' id='select-tables'> 
<option value="mytable">Survey Test Table</option> 
<option value="mytableSurvey">Survey Only</option> 
</select> 
</br> 


<script type="text/javascript"> 
(function($) { 
$(document).ready(function() { 

$('#mytable').DataTable({ 
dom: 'Blfrtip', 
buttons: [ 
'copy', 'excel', 'pdf', 'colvis' 
] 
}); 

$('a.toggle-vis').on('click', function (e) { 
e.preventDefault(); 

// Get the column API object 
var column = table.column($(this).attr('data-column')); 

// Toggle the visibility 
column.visible(! column.visible()); 

});

$('#mytableSurvey').DataTable({ 
dom: 'Blfrtip', 
buttons: [ 
'copy', 'excel', 'pdf', 'colvis' 
] 
}); 
$('.dataTable').wrap('<div class="dataTables_scroll" />'); 




$(document).on('change' , '#select-tables', function(){ 
var table = $(this).val(); 
$('#' + table +'_wrapper').show(); 
$('[id$="_wrapper"]').not('#' + table +'_wrapper').hide(); 
}); 
$("#select-tables").trigger("change"); 

}); 
}(jQuery)); 
</script> 
+0

尽量帮助你,你是否尝试过他们的[发电机](https://editor.datatables.net/generator/)? – jlynch630

+0

我其实没有。你有任何使用WordPress的经验吗? –

+0

没有,但是设置似乎很简单。他们写信只是改变包含的PHP文件连接到您的数据库。 – jlynch630

回答

0

这不是一个完整的答案,而是一种指向不使用数据表编辑器的解决方案。过去我曾这样做过。

如果您对ajax有一些经验,您可以在数据表中创建一行,并在其中包含具有行ID的属性的按钮。然后设置一个onclick事件来发送ajax trequest到一个函数,该函数从数据库中删除具有该ID的行。

对于编辑我使用了https://vitalets.github.io/x-editable/它有一个非常简单的API。

如果你想要更多的帮助,我可以通过chat