如何在php中显示(回声)选择的值?

问题描述 投票:-3回答:2

如何显示mysql_query中的值或将其保存在一个变量中?目前我得到的是资源id #4。

$currentpointsquery = "SELECT user_points FROM points WHERE user_id = '$user_id';";
$currentpointsquery2 = mysql_query($currentpointsquery);
echo(currentpointsquery2);
php echo
2个回答
0
投票
echo($currentpointsquery2);

这里你试图打印一个 mysql 资源变量 而不是它所引用的资源中的值。该 mysql_fetch_array() 函数以关联数组或数字数组的形式从记录集中返回一行。所以可以尝试用

echo $currentpoints[0];

 echo $currentpoints['user_points'];

1
投票

试试吧

$currentpointsquery = "SELECT user_points FROM points WHERE user_id = '$user_id'";
$currentpointsquery2 = mysql_query($currentpointsquery);
$currentpoints = mysql_fetch_array($currentpointsquery2);
echo $currentpoints['user_points'];
© www.soinside.com 2019 - 2024. All rights reserved.