开发者

How do I select one row from a MySQL table?

开发者 https://www.devze.com 2023-03-22 16:27 出处:网络
If I know the query only returns one row, and more specefically, in this case one value, 开发者_如何学运维$full_name = database::query(\"SELECT concat (fname, \' \', lname) from cr WHERE email=\'$em

If I know the query only returns one row, and more specefically, in this case one value,

开发者_如何学运维$full_name = database::query("SELECT concat (fname, ' ', lname) from cr WHERE email='$email'");

how do I get that value into a single variable. Database::query returns the value form mysql_query. The query above insert "Resource ID 4" in to mysql table.

How do I select one row from a MySQL table?

How do I select one row from a MySQL table?


I don't know about database::query(), but mysql_query() does indeed return a resource.

Once you have that resource, you must fetch your data from it, using, for example, mysql_fetch_array() :

$data = mysql_fetch_array($full_name);


Note that there are several mysql_fetch_* function, depending on what kind of result your want (array, object, ...) :

  • mysql_fetch_row()
  • mysql_fetch_object()
  • mysql_fetch_assoc()


$query = mysql_query("SELECT concat (fname, ' ', lname) from cr WHERE email='$email'");
$row = mysql_fetch_row($query);
echo $row[0]; 


I'm not sure what else your database class has to offer, but using built in php mysql function you could use:

$full_name = database::query("SELECT concat (fname, ' ', lname)
     from cr WHERE email='$email'");
$full_name = mysql_fetch_row($full_name);
$full_name = $full_name[0];
0

精彩评论

暂无评论...
验证码 换一张
取 消