dongliao1949 2015-10-09 04:43
浏览 47
已采纳

如何编辑循环MySQL数据?

i got correct saveID but TemplateData and TitleData it only copy first row data even i change to something else. saveID is unique id of the data. what i need is when i changed it capture the data not first column data.

        <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

  • 写回答

3条回答 默认 最新

  • douzhanglun4482 2015-10-09 05:15
    关注

    your text box ids are same so please add id to textboxes like

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

    and fetch like

    var TitleData = $("#TitleData"+saveID).val();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合