textarea的不与阿贾克斯存储新行的更新 [英] Textarea not storing the newline in update with ajax
问题描述
我有一些文本形式存储在MySQL表以下格式:
- 这是演示行1
- 这是演示2号线
- 这是演示3号线
- 这是演示4号线
- 这是演示线5
但是,当我更新了文本区域的任何行,它会显示以下output.Actually,我试图做一个文本文件,如果我不将其更新到输出我在一个文本上述内容文件,但,当我更新的内容给我下面的输出文本文件。
下面是我的code:
这是演示1号线 这是演示线2此为演示线3本为演示线4本为演示线5
<表>
< TR类=头>
百分位风格=显示:无>吊牌名称和LT; /第i个
百分位风格=显示:无>标签详情< /第i个
< / TR>
< PHP
$ SQL1 =SELECT * FROM tagto_print那里print_tag_id ='8';
$ reslabel =请求mysql_query($ SQL1);
$ i = 1;
而($行= mysql_fetch_array($ reslabel))
{
$ printid = $行['print_tag_id'];
$ tagdetailstoprint = $行['print_tag_details'];
?>
< TR ID =< PHP的echo $ printid;>中类=edit_tr>
< TD宽度=10%>< PHP的echo $行['print_tag_labelname'];?>< / TD>
&所述; TD宽度=50%类=edit_td>
<跨度ID =details_<?PHP的echo $ printid;>中类=文本>< pre>< PHP的echo $ tagdetailstoprint; ?>< / pre>< / SPAN>
< TextArea类=表单控制ID =details_input_<?PHP的echo $ printid;>中行=8> <?PHP的echo $ tagdetailstoprint; ?>< / textarea的>< / TD>
< / TR>
< PHP
$ I ++;
}
?>
< /表>
<风格>
.FORM控制
{
显示:无;
}
< /风格>
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数()
{
$(edit_tr)。点击(函数()
{
VAR ID = $(本).attr('身份证');
$(#细节_+ ID)的.hide();
$(#details_input _+ ID)的.show();
})。改变(函数()
{
VAR ID = $(本).attr('身份证');
VAR tagdetailsarea = $(#details_input _+ ID).VAL();
VAR dataString ='printid ='+ ID +'和; printdetails ='+ tagdetailsarea;
$(#细节_+ ID)的.html('< IMG SRC =load.gif/>');
如果(tagdetailsarea.length大于0)
{
$阿贾克斯({
键入:POST,
网址:打印标签-edit.php的,
数据:dataString,
缓存:假的,
成功:函数(HTML)
{
$(#细节_+ ID)的.html(tagdetailsarea);
}
});
}
其他
{
警报(你不能打印空白数据);
}
});
$(形式控制)。鼠标松开(函数()
{
返回false
});
$(文件).mouseup(函数()
{
$(形式的控制。)隐藏()。
$(文本)显示();
});
});
< / SCRIPT>
文件更新打印标签-edit.php的:
< PHP
如果($ _ POST ['printid'])
{
的$ id = $ _ POST ['printid'];
$细节= $ _ POST ['printdetails'];
$ SQL =更新tagto_print集print_tag_details ='$详细信息,其中print_tag_id ='的$ id';
的mysql_query($ SQL);
}
?>
我整理我的问题。该解决方案是多次提到的组合。我拿来从表中的记录,并把(BR)的含量
$ tagdetailstoprint = $行['print_tag_details'];
$符= nl2br($ tagdetailstoprint);
$文字= str_replace函数($符\ r \ N,$ tagdetailstoprint);
在我的textarea,我这样做:
< TextArea类=表单控制ID =details_input_<?PHP的echo $ printid;>中行=8> <?PHP的回声用htmlspecialchars($文本); ?>< / textarea的>
和风格,我加的,并建议样式表
<风格>
。文本{
空格:pre系列;
}
< /风格>
在我的文件更新打印标签-edit.php的,我这样做:
$细节= nl2br($ _ POST ['printdetails']); //我存储在nl2br在我的MySQL表
这code是创建的文本文件:
$今天=日期(Y-M-D-Hi的);
标题(内容类型:应用程序/八位字节流);
标题(内容处置:附件;文件名=$今天_为Backup.txt);
$查询=SELECT * FROM tagto_print,其中print_tag_id ='8';
$结果= mysql_query($查询);
$数据=;
$场所=阵列(&所述峰; br />中,&所述峰; br>中,&所述峰; br />中); //我把BR阵
而($行= mysql_fetch_object($结果)){
$文字= str_replace函数($符\ r \ N,$行向> print_tag_details); //并条代替它与\ r \ N
。$数据={$文字};
。$数据=\ r \ N的;
}
回声$的数据;
出口;
}
I have some text stored in mysql table in below format:
- This is the demo line 1
- This is the demo line 2
- This is the demo line 3
- This is the demo line 4
- This is the demo line 5
but, when I update any line in the text area, it displays the below output.Actually, I'm trying to make a text file with this if I don't update it to output me the above content in a text file but, When I update the content to give me the below output in the text file.
Here is my code:
This is the demo line 1 This is the demo line 2This is the demo line 3This is the demo line 4This is the demo line 5
<table>
<tr class="head">
<th style="display: none">Lable Name</th>
<th style="display: none">Tag Details</th>
</tr>
<?php
$sql1 = "SELECT * from tagto_print where print_tag_id='8'";
$reslabel=mysql_query($sql1);
$i=1;
while($row=mysql_fetch_array($reslabel))
{
$printid=$row['print_tag_id'];
$tagdetailstoprint=$row['print_tag_details'];
?>
<tr id="<?php echo $printid; ?>" class="edit_tr">
<td width="10%"><?php echo $row['print_tag_labelname'];?></td>
<td width="50%" class="edit_td">
<span id="details_<?php echo $printid; ?>" class="text"><pre><?php echo $tagdetailstoprint; ?></pre></span>
<textarea class="form-control" id="details_input_<?php echo $printid; ?>" rows="8"> <?php echo $tagdetailstoprint; ?></textarea></td>
</tr>
<?php
$i++;
}
?>
</table>
<style>
.form-control
{
display:none;
}
</style>
<script type="text/javascript">
$(document).ready(function()
{
$(".edit_tr").click(function()
{
var ID=$(this).attr('id');
$("#details_"+ID).hide();
$("#details_input_"+ID).show();
}).change(function()
{
var ID=$(this).attr('id');
var tagdetailsarea=$("#details_input_"+ID).val();
var dataString = 'printid='+ ID +'&printdetails='+tagdetailsarea;
$("#details_"+ID).html('<img src="load.gif" />');
if(tagdetailsarea.length>0)
{
$.ajax({
type: "POST",
url: "print-tags-edit.php",
data: dataString,
cache: false,
success: function(html)
{
$("#details_"+ID).html(tagdetailsarea);
}
});
}
else
{
alert('You can not Print Blank Data');
}
});
$(".form-control").mouseup(function()
{
return false
});
$(document).mouseup(function()
{
$(".form-control").hide();
$(".text").show();
});
});
</script>
File to update print-tags-edit.php:
<?php
if($_POST['printid'])
{
$id=$_POST['printid'];
$details=$_POST['printdetails'];
$sql = "update tagto_print set print_tag_details='$details' where print_tag_id='$id'";
mysql_query($sql);
}
?>
I sorted my problem. This solution is mix of many references. I fetched the record from the table and put the (br) in content
$tagdetailstoprint=$row['print_tag_details'];
$breaks = nl2br($tagdetailstoprint);
$text = str_replace($breaks, "\r\n", $tagdetailstoprint);
In my textarea, I did this:
<textarea class="form-control" id="details_input_<?php echo $printid; ?>" rows="8"> <?php echo htmlspecialchars($text); ?></textarea>
and in style, I added the style sheet suggested by the AND
<style>
.text{
white-space: pre-line;
}
</style>
In my file to update print-tags-edit.php, I did this:
$details=nl2br($_POST['printdetails']); // i stored the nl2br in my mysql table
This code is to create the text file:
$today = date("Y-m-d-Hi");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$today."_Backup.txt");
$query = "SELECT * FROM tagto_print where print_tag_id='8'";
$result = mysql_query($query);
$data = "";
$breaks = array("<br />","<br>","<br/>"); // i put the br in array
while ($row=mysql_fetch_object($result)) {
$text = str_replace($breaks, "\r\n", $row->print_tag_details); // and repalced it with the "\r\n"
$data .= "{$text}";
$data .="\r\n";
}
echo $data;
exit;
}
这篇关于textarea的不与阿贾克斯存储新行的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!