简体   繁体   English

从MySQL表中回显单个值

[英]echo single value from mysql table

I've been driving myself mad with this for the last hour. 在过去的一个小时里,我一直对此感到生气。 It should be so easy but I just cannot work it out: 它应该很简单,但我无法解决:

All I am trying to do is echo 1 value (in column "active") from a mysql table where the column "name" is equal to "GSHP". 我想要做的就是从mysql表中的“名称”等于“ GSHP”的mysql表中回显1值(在“活动”列中)。

This is what I have. 这就是我所拥有的。 Can anyone please help? 谁能帮忙吗?

$query = "SELECT active FROM discount WHERE name = GSHP";

        $result = mysql_query($query);

        $row = mysql_fetch_array($result);

        echo $row['active'];

In SQL you need to fit string literals into quotes. 在SQL中,您需要将字符串文字放入引号中。 Your query should look like: 您的查询应类似于:

$query = "SELECT active FROM discount WHERE name = 'GSHP'";

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

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