简体   繁体   English

在段落中显示mysql内容时出现问题

[英]Problem displaying the mysql content in Paragraphs

I insert questions(which might be a few paragraphs) in a sql table using php and than i diplay them on a webpage. 我使用php在sql表中插入问题(可能是几段),然后在网页上显示这些问题。

but when i display the question it loses its formatting. 但是当我显示问题时,它会失去格式。 I mean it will just show the whole question in one paragraph, even thou there were many paragraphs before. 我的意思是,即使您之前有很多段落,它也只会在一个段落中显示整个问题。

<td width=\"700px\" bgcolor=\"#EAD57F\"><font color=\"#4A2A0B\">Question :</font><font color=\"#5E450B\">".$row2['Question']."</font></td>

$row2['Question'] --> is my question that i am getting from my sql table by running the SELECT query. $ row2 ['Question']->是我的问题,我是通过运行SELECT查询从sql表中获取的。

So if i post something like : asdf 所以,如果我发布类似:asdf

into my input box. 进入我的输入框

the output looks like : asdf 输出如下:asdf

How should i resolve this? 我该如何解决?

Best Zeeshan 最好的Zeeshan

You probably save your paragraphs separated by a "new line" character. 您可能保存了用“换行”字符分隔的段落。 To translate that in HTML check the nl2br PHP function (in HTML new line is the <br /> tag). 要在HTML中进行翻译,请检查nl2br PHP函数(在HTML中,新行是<br />标记)。

Are you storing them as plain text, or do they contain HTML tags? 您是将它们存储为纯文本格式,还是包含HTML标签? If they are stored as plain text you should put them in a <pre> tag or something equivalent in order to preserve the spacing. 如果将它们存储为纯文本,则应将它们放在<pre>标记或等效标记中,以保留间距。 Alternatively, you could do the encoding into HTML, putting in <p> tags and such where necessary, but that is complicated and easy to get wrong. 或者,您可以将编码编码为HTML,在必要时放入<p>标记等,但这很复杂且容易出错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM