php - mysql 查询不显示结果

标签 php mysql

mysql 新手。我有一个查询,它不显示单元格的值,只显示行名称:

$sql="SELECT 'first' from `users` WHERE `id`= $userid ";
$res=mysql_query($sql) or die(mysql_error());

$row=mysql_fetch_assoc($res); 

echo $row['first'] ; 

我做错了什么???

最佳答案

您的查询中的括号错误:

$sql = "SELECT 'first' from `users` WHERE `id` = $userid";

必须是:

$sql = "SELECT `first` from `users` WHERE `id` = $userid";

注意首先的区别

关于php - mysql 查询不显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3564635/

相关文章:

php - Laravel:将参数传递给关系函数?

php - php 网站的架构帮助

php - CakePhp 确实更新而不是插入新数据

php - 在 PHP 中将数字序列转换为数组

php - 禁止在 PHP 中覆盖变量

php - 嵌套多级类别的更动态的方式

mysql - Chef Recipe 将值添加到 mysql 表

mysql - 我如何追踪玩家的胜利?

mysql - SQL ALTER TABLE 排除列

php - jquery向下滑动-向上滑动的表单-第一次默认隐藏,