如何使用ajax从表td中删除mysql DB中的数据?
我的目标是删除通讯员 使用 AJAX 获取 mysql 数据库表中的数据。 所以我生成了一个包含多行的表,并且想要一个非特定行...
PHP 代码:
<?php
if(isset($_SESSION['login_status'])){
require 'classes/datahandle.class.php';
$data = new Datahandle();
$query = "
SELECT
e.place,
e.id_station,
g.description,
ac.max, ac.min,
ac.mensagem
FROM unit g, tableA ac, station e
WHERE client = '" . $_SESSION['user_id'] . "'
AND ac.unit=g.field
AND ac.id_station=e.id_station
";
$result = $data->selectDataQuery($query);
$numRows = $data->getAffectedRows();
if($numRows > 0){
?>
<table id="consAlerts" border="0" align="center">
<tr>
<td style="text-align: center; color: white; font-weight: bold;">Value 1</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 2</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 3</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 4</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 5</td>
<td colspan="2"></td>
</tr>
<?php
while ($alert = mysql_fetch_array($result)) {
?>
<tr>
<td>
<select class="stationCons" disabled="disabled">
<?php
$query = "SELECT id_station,place FROM station";
$queryResult = $data->selectDataQuery($query);
while($option = mysql_fetch_array($queryResult)){
if($alert['id_station'] == $option['id_station']){
?>
<option value="<?php echo $option['id_station']?>" selected ><?php echo $option['place']?></option>
<?php
}if($alert['id_station'] != $option['id_station']){
?>
<option value="<?php echo $option['id_station']?>"><?php echo $option['place']?></option>
<?php
}
}
?>
</select>
</td>
<td>
<select class="unitCons" disabled="disabled">
<?php
$query = "SELECT field, description FROM unit";
$queryResult = $data->selectDataQuery($query);
while($option = mysql_fetch_array($queryResult)){
if($alert['description'] == $option['description']){
?>
<option value="<?php echo $option['field']?>" selected="selected"><?php echo $option['description']?></option>
<?php
}if($alert['description'] != $option['description']){
?>
<option value="<?php echo $option['field']?>"><?php echo $option['description']?></option>
<?php
}
}
?>
</select>
</td>
<td>
<input type="text" class="consMax" value="<?php echo $alert['max'] ?>"/>
</td>
<td>
<input type="text" class="consMin" value="<?php echo $alert['min'] ?>"/>
</td>
<td>
<input type="text" class="msg" value="<?php echo $alert['mensagem'] ?>"/>
</td>
<td>
<input type="submit" class="delete" value="Delete"/>
</td>
<td>
<input type="submit" class="edit" value="Edit"/>
</td>
</tr>
<?php
}
?>
</table>
<?php
}if ($numRows == 0) {?>
<div style="color:#FFF; font-weight:bold; padding:10px; text-align:center;">Sometext</div>
<?php
}
} else
echo "<meta http-equiv='refresh' content='1; URL=../index.php'>";
?>
JQUERY:
<script type="text/javascript">
<!--
$(document).ready(function() {
$(".delete").click(function(){
//AJAX CALL
$.post("phpValidationScript.php", { station:$(".stationCons").val(), grandeza:$(".unitCons").val(), consMax:$(".consMax").val(), consMin:$(".consMin").val(), msg:$(".msg").val() }, function(data){
alert(data);
});
});
return false;
});
//-->
</script>
我的代码仅删除第一行... 如何参考正确的 td 值? 并将它们传递给ajax?
编辑: 我收到此错误: TypeError: object is not a function [http://127.0.0.1/somesite/index.php?page=consAlerts:[35]
该错误指的是以下代码:
$.post("validaConsApagar.php", { estacao:$(this)(".estacaoCons").val(), grandeza:$(this)(".grandezaCons").val()}, function(data){...
所以这不是一个函数,这意味着语法错误?
My goal here is to delete the correspondent <td> data in mysql db table using AJAX.
So I've generated a table with several rows and want to a non specific row...
PHP Code:
<?php
if(isset($_SESSION['login_status'])){
require 'classes/datahandle.class.php';
$data = new Datahandle();
$query = "
SELECT
e.place,
e.id_station,
g.description,
ac.max, ac.min,
ac.mensagem
FROM unit g, tableA ac, station e
WHERE client = '" . $_SESSION['user_id'] . "'
AND ac.unit=g.field
AND ac.id_station=e.id_station
";
$result = $data->selectDataQuery($query);
$numRows = $data->getAffectedRows();
if($numRows > 0){
?>
<table id="consAlerts" border="0" align="center">
<tr>
<td style="text-align: center; color: white; font-weight: bold;">Value 1</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 2</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 3</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 4</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 5</td>
<td colspan="2"></td>
</tr>
<?php
while ($alert = mysql_fetch_array($result)) {
?>
<tr>
<td>
<select class="stationCons" disabled="disabled">
<?php
$query = "SELECT id_station,place FROM station";
$queryResult = $data->selectDataQuery($query);
while($option = mysql_fetch_array($queryResult)){
if($alert['id_station'] == $option['id_station']){
?>
<option value="<?php echo $option['id_station']?>" selected ><?php echo $option['place']?></option>
<?php
}if($alert['id_station'] != $option['id_station']){
?>
<option value="<?php echo $option['id_station']?>"><?php echo $option['place']?></option>
<?php
}
}
?>
</select>
</td>
<td>
<select class="unitCons" disabled="disabled">
<?php
$query = "SELECT field, description FROM unit";
$queryResult = $data->selectDataQuery($query);
while($option = mysql_fetch_array($queryResult)){
if($alert['description'] == $option['description']){
?>
<option value="<?php echo $option['field']?>" selected="selected"><?php echo $option['description']?></option>
<?php
}if($alert['description'] != $option['description']){
?>
<option value="<?php echo $option['field']?>"><?php echo $option['description']?></option>
<?php
}
}
?>
</select>
</td>
<td>
<input type="text" class="consMax" value="<?php echo $alert['max'] ?>"/>
</td>
<td>
<input type="text" class="consMin" value="<?php echo $alert['min'] ?>"/>
</td>
<td>
<input type="text" class="msg" value="<?php echo $alert['mensagem'] ?>"/>
</td>
<td>
<input type="submit" class="delete" value="Delete"/>
</td>
<td>
<input type="submit" class="edit" value="Edit"/>
</td>
</tr>
<?php
}
?>
</table>
<?php
}if ($numRows == 0) {?>
<div style="color:#FFF; font-weight:bold; padding:10px; text-align:center;">Sometext</div>
<?php
}
} else
echo "<meta http-equiv='refresh' content='1; URL=../index.php'>";
?>
JQUERY:
<script type="text/javascript">
<!--
$(document).ready(function() {
$(".delete").click(function(){
//AJAX CALL
$.post("phpValidationScript.php", { station:$(".stationCons").val(), grandeza:$(".unitCons").val(), consMax:$(".consMax").val(), consMin:$(".consMin").val(), msg:$(".msg").val() }, function(data){
alert(data);
});
});
return false;
});
//-->
</script>
My code deletes ONLY the first row...
How can I refer to the proper td values?
And pass them to the ajax?
EDIT:
I'm getting this error:
TypeError: object is not a function [http://127.0.0.1/somesite/index.php?page=consAlerts:[35]
The error refers to the bellow code:
$.post("validaConsApagar.php", { estacao:$(this)(".estacaoCons").val(), grandeza:$(this)(".grandezaCons").val()}, function(data){...
So this is not a function that means that the syntax is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用该运算符。
use this operator.