如何将百分号添加到sql查询的字符串值输出中

时间:2022-05-18 20:53:56

This is probably more simple than I think, but I'm having a really hard time wrapping my head around this. I've been trying to learn how to code after a 10 year hiatus from it, so hacking and codecademy are my teachers. Anyways, ...

这可能比我想的要简单,但我真的很难把我的脑袋绕在这上面。我一直在努力学习如何在中断10年之后编写代码,所以黑客和codecademy是我的老师。无论如何,…

What I'm trying to do is simply make a whole number from an sql entry a percentage.

我要做的就是从一个sql条目中提取一个完整的数字。

I have a form which when submitted enters an sql value whole number that is used to output a css value. I'm only trying to change the width value from a whole number to a percentage to allow some semblance for a responsive effect.

我有一个表单,提交时输入一个sql值整数值,用于输出一个css值。我只是想把宽度值从一个整数改为百分数,以使响应效果看起来更接近。

Here's the php pre-output:

这是php pre-output:

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

The output is as follows:

输出如下:

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

Thanks in advance for any help!

谢谢你的帮助!

3 个解决方案

#1


2  

If you are using mysql, you could use the CONCAT() function to add some character to the end of a specific field.

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

CONCAT(str1,str2,...) - Returns the string that results from concatenating the arguments.

CONCAT(str1,str2,…)——返回连接参数的字符串。

For example -

例如,

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

Now, what ever value was stored in the percentage field will have a % character appended to it in the result set.

现在,在百分比字段中存储的值将在结果集中添加一个%字符。

#2


2  

I guess this is not an issue of your coding.

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

May I assume that you got this:

我可以假设你得到了这个吗:

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

..via a tool like firebug/developer-tools?

. .通过像firebug/developer-tools这样的工具?

When yes, this is not the original source, there has been a cleanup of invalid parts.

如果是,这不是原始的源代码,就会清除无效的部分。

One of them is the percent-sign, it's not valid inside the width-attribute. To get the desired result, use css instead:

其中一个是百分号,它在width属性中无效。要得到想要的结果,可以使用css:

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

#3


0  

Use this:

用这个:

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

#1


2  

If you are using mysql, you could use the CONCAT() function to add some character to the end of a specific field.

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

CONCAT(str1,str2,...) - Returns the string that results from concatenating the arguments.

CONCAT(str1,str2,…)——返回连接参数的字符串。

For example -

例如,

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

Now, what ever value was stored in the percentage field will have a % character appended to it in the result set.

现在,在百分比字段中存储的值将在结果集中添加一个%字符。

#2


2  

I guess this is not an issue of your coding.

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

May I assume that you got this:

我可以假设你得到了这个吗:

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

..via a tool like firebug/developer-tools?

. .通过像firebug/developer-tools这样的工具?

When yes, this is not the original source, there has been a cleanup of invalid parts.

如果是,这不是原始的源代码,就会清除无效的部分。

One of them is the percent-sign, it's not valid inside the width-attribute. To get the desired result, use css instead:

其中一个是百分号,它在width属性中无效。要得到想要的结果,可以使用css:

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

#3


0  

Use this:

用这个:

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