可能重复:mysql_fetch_array()期望参数1是资源,在select中给出布尔值
if (isset($_GET['uid']) && !empty($_GET['uid'])) {
$id = $_GET['uid'];
$sql = "SELECT * FROM `apps` WHERE `id` = ". mysql_real_escape_string($id) ." LIMIT 1";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result) == 1) {
while($row = mysql_fetch_assoc($result)){
$username = $row["MCName"];
echo'
//Here is a ton of rows and some html.
';
}
$sql = "SELECT * FROM `apps` WHERE `MCName` = ". $username;
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
}else {
die('Record not found.');
}
}
}
我尝试了一切,它一直在失败 . 我不是SQL和PHP的主人 . 我想用“MCName”计算有多少行我不确定我是否可以在第一个SQL查询中执行此操作 . 此外,错误出现在第44行,也就是执行mysql_num_rows的行 . DB在脚本的早期连接 .
对不起,如果这是一个非常愚蠢的问题,请相信我 . 我搜索了一个小时左右来修复^^
3 回答
您的第二个查询有SQL语法错误:
$username
变量需要用引号括起来 . 尝试更新以下内容以修复:这是来自php:http://php.net/manual/en/function.mysql-query.php
Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
有关详细示例,请参阅http://www.php.net/manual/en/mysqli.query.php
正确的方法吗?
然后从中得到你的结果 .
是的,我建议使用PDO而不是mysql_ *命令