如何向SQL查询输出的字符串值添加百分比符号


how to add a percent symbol to a string value output from sql query

这可能比我想象的更简单,但我真的很难理解这一点。在中断编程10年之后,我一直在努力学习如何编程,所以hacking和codecademy是我的老师。无论如何,…

我想做的就是简单地从sql条目中得到一个整数作为百分比。

我有一个表单,当提交时输入一个sql值整数,用于输出css值。我只是试图改变宽度值从一个整数到一个百分比,以允许一些类似的响应效果。

下面是php的预输出:

        <video id="vp2_html5_rightSidePlaylist_'.$row["id"].'" width="'.$row["playerWidth"].'%" height="'.$row["playerHeight"].'" '.$preload_aux.'><div class="xplaylist">'.$playlist_str.'</div></video>

输出如下:

        <video id="vp2_html5_rightSidePlaylist_1" width="100" height="297" preload="auto" src="http://localhost:888/test.mp4">

提前感谢您的帮助!

如果您正在使用mysql,您可以使用CONCAT()函数在特定字段的末尾添加一些字符。

CONCAT(str1,str2,...) -返回参数连接后的字符串。

例如-

SELECT `id`,`title`,CONCAT(`percentage`,'%') as percentage FROM `items` LIMIT 100

现在,在percentage字段中存储的任何值都将在结果集中附加一个%字符。

我猜这不是你编码的问题。

我可以假设你收到了这个吗?

<video id="vp2_html5_rightSidePlaylist_1" width="100" height="297" preload="auto" src="http://localhost:888/test.mp4">

. .通过firebug/developer-tools之类的工具?

如果是,这不是原始源,则已清理了无效部分。

其中之一是百分号,它在width属性中无效。为了得到想要的结果,使用css代替:

'style="width:'.$row["playerWidth"].'%;height:'.$row["playerHeight"].'px;"'

使用

Select CONCAT(`playerWidth`,'%') AS playerWidth, id .....etc FROM tableName