从MySQL数据库的一行中读取一列 [英] Read one column from one row from a MySQL database
问题描述
是否有一种快速而肮脏的方法来从一行中获取一列的值?现在我用这样的东西:
Is there a quick and dirty way to get the value of one column from one row? Right now I use something like this:
$result = mysql_query("SELECT value FROM table WHERE row_id='1'");
$row = mysql_fetch_array($result);
return $row['value'];
似乎必须能够合并第二行和第三行.
It seems there must be able to consolidate the second and third lines.
这三行代码似乎很多,仅仅是为了从一行中的一列中获取值.我试过了:
These three lines seem like a lot just to get the value from one column from one row. I tried this:
$ result = mysql_query(从表WHERE row_id ='1'"中选择值); 返回mysql_fetch_array($ result)['value'];
$result = mysql_query("SELECT value FROM table WHERE row_id='1'"); return mysql_fetch_array($result)['value'];
但这不起作用.我只是想找出是否有一种更简单,更重要的方式来获得这样的价值.
But that doesn't work. I am just trying to find out if there is a simpler, more to the point, way of getting one value like this.
推荐答案
使用此:
$result = mysql_query("SELECT value FROM table WHERE row_id='1'");
return mysql_result($result, 0);
这篇关于从MySQL数据库的一行中读取一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!