Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 警告:mysql_num_rows()希望参数1是资源,第14行给出的布尔值_Php_Mysql_Sql - Fatal编程技术网

Php 警告:mysql_num_rows()希望参数1是资源,第14行给出的布尔值

Php 警告:mysql_num_rows()希望参数1是资源,第14行给出的布尔值,php,mysql,sql,Php,Mysql,Sql,当尝试使用此代码时,我得到了此错误。我可以在不同的数据库上使用完全相同的代码和不同的表名,而且效果很好 <?php $getid = $_GET['id']; if (!$getid) $getid = "1"; require('scripts/connect.php'); $query = mysql_query("SELECT * FROM team

当尝试使用此代码时,我得到了此错误。我可以在不同的数据库上使用完全相同的代码和不同的表名,而且效果很好

<?php

            $getid = $_GET['id'];

            if (!$getid)
                $getid = "1";

            require('scripts/connect.php');
            $query = mysql_query("SELECT * FROM team WHERE id='$getid'");
            $numrows = mysql_num_rows($query);

            if($numrows == 1){
                $row = mysql_fetch_assoc($query);
                $id = $row['id'];
                $firstname = $row['first_name'];
                $lastname = $row['last_name'];
                $position = $row['position'];
                $bats = $row['bats'];
                $throws = $row['throws'];
                $number = $row['number'];
                $picture = $row['picture'];


                echo "<div id='team'>

问题出在这个查询上

SELECT * FROM team WHERE id>=1 DESC LIMIT 10
                            // ^ Error on this line
您忘记添加
orderby
子句

SELECT * 
FROM   team 
WHERE  id>=1 
ORDER  BY ID DESC  // change the column name with your original one.
LIMIT  10
只需替换查询即可 有了这个疑问

        $query = mysql_query("SELECT * FROM   team WHERE  id>=1 
        ORDER BY id DESC  LIMIT  10 ");

错误“期望参数1是资源,布尔给定的”背后的原因是当您执行错误的查询时,它失败,它返回0,这就是“布尔给定”的原因

@JW指出了一个原因,并用以下内容更正了查询:

SELECT * 
FROM   team 
WHERE  id>=1 
ORDER  BY id DESC  // change the column name with your original one.
LIMIT  10

但是,如果得到的结果相同,那么查询本身也会出错。可能的原因可能是:错误的表名、错误的列名等。

将其更改为此错误和相同的错误。(“从id>=1的团队中选择*按id描述订单限制10”)谢谢,是的,我刚刚从我的服务提供商那里找到了它。由于它是一个新的数据库和用户名,用户出于某种原因不会链接到数据库。因此,它不会选择表/db来实际执行查询。在我知道我的查询是正确的之后,我通过在sql中的myphpadmin上检查它们联系了他们。不客气。很高兴这有帮助:)
SELECT * 
FROM   team 
WHERE  id>=1 
ORDER  BY id DESC  // change the column name with your original one.
LIMIT  10