gpt4 book ai didi

javascript - 如何编辑循环MySQL数据?

转载 作者:行者123 更新时间:2023-11-29 11:57:06 24 4
gpt4 key购买 nike

我得到了正确的 saveID,但 TemplateData 和 TitleData 即使我更改为其他内容,它也只复制第一行数据。 saveID是数据的唯一ID。我需要的是当我更改它时捕获数据而不是第一列数据。

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

$(".save_button").click(function (e) {
e.preventDefault();
var saveID =$(this).val();
var url_tna = "<?php echo $_SESSION['url_address'];?>mods/agent_management/code/";


var TitleData =$("#TitleData").val(); //build a post data structure
var TemplateData =$("#TemplateData").val();
var IdData =$("#IdData").val();
alert(saveID);
alert(TemplateData);
alert(TitleData);
var JsonData = {TitleData: TitleData, TemplateData: TemplateData, saveID: saveID};

jQuery.ajax({
type: "POST", // Post Get method
url: url_tna+"email_template_response.php", //Where form data is sent on submission
dataType:"text", // Data type, HTML, json etc.
data:JsonData, //Form variables
success:function(response){
window.location.reload(true); // reload before append
$("#responds").append(response);
document.getElementById("contentText").value = "";
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
});
</script>

<table>

<tr>
<td>No</td>
<td>Title</td>
<td>Template</td>
<td>Recipents</td>
<td>Schedule</td>
</tr>
<?php $i=1; while ($row = mysql_fetch_array($result)) { ?>


<tr>
<td><?php echo $i; ?></td>

<td><textarea type="textarea" id="TitleData" name="TitleData" class="1"><?php echo $row['title'];?></textarea></td>
<td><textarea type="textarea" id="TemplateData" name="TemplateData" class="1"><?php echo $row['template'];?></textarea></td>
<td><button id="recipant"><a id="myLink" href="email_template.php?id=<?php echo $row['id']; ;?>" target="_blank">Open Recipant</a> </button></td>
<td><button id="shedule"><a id="myLink" href="email_schedule.php?id=<?php echo $row['id']; ;?>" target="_blank">Open Shedule</a></button></td>
<td><input type="hidden" id="IdData" class="save_button1" name="txtLink" value="<?php echo $row['id']; ?>"></input></td>
<td><button id="SaveTemplate" name="SaveTemplate" class="save_button" value="<?php echo $row['id'];?>"><a href="#" style="display:block" class="button insertcolumn" id="<?php echo $row['id'];?>">Save</a></button></td>
<td><button >Sent Mail Now</button></td>
</tr>
<? $i++; }?>

</table>

if (!empty($saveID)) {
$sql2 = "UPDATE at_agent_template set title = '$TitleData', template= '$TemplateData' where id = '$saveID'";
$result2 = mysql_query($sql2);
}

enter image description here

最佳答案

您的文本框 ID 相同,因此请将 ID 添加到文本框就像

<td><textarea type="textarea" id="TitleData<?php echo $row['id'];?>" name="TitleData" class="1"><?php echo $row['title'];?></textarea></td>

并获取类似

var TitleData = $("#TitleData"+saveID).val();

关于javascript - 如何编辑循环MySQL数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33030060/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com