-3

可能重复:
PHP:警告:sort() 期望参数 1 是数组,资源给定

我有以下 PHP 代码,但收到此错误。我尝试了不同的解决方案,但似乎不起作用。任何帮助将不胜感激。

<?php
INCLUDE 'functions.php' ;

$host = 'localhost';    
$id = '***';    
$pwd = '***';    
$db = '****'; 

$myconnection = connect_db($host, $id, $pwd, $db);

$SortOn = $_POST["SortOn"];    
$SortIn = $_POST["SortIn"];


$sql = "SELECT ID, DateTime, FirstName, LastName, AdditionalInformation, Category1,    Category2, Category3, Category4, Category5, Pending, Approved, Disapproved, WebsiteName, WebsiteURL FROM 'websites' ORDER BY $SortOn $SortIn";
echo "<table border=\"1\"><tr><th>ID</th><th>Date & Time</th><th>First Name</th><th>Last Name</th><th>Additional Information</th><th>Category 1</th><th>Category 2</th><th>Category 3</th><th>Category 4</th><th>Category 5</th><th>Pending</th><th>Approved</th><th>Disapproved</th><th>Website Name</th><th>Website URL</th></tr>";

$result = mysql_query($sql);            



while ( $row = mysql_fetch_array($result))            
{                
    echo "<tr>";        
    for ( $column = 0;$column < count($row);$column++)        
    {            
        echo "<td>" . $row[$column] . "</td>";        
    }        
    echo "</tr>";    


}            
echo "</table>";

?>   
4

3 回答 3

0

这个变量$result给了你一个布尔值(可能它会返回一个 False 或类似的东西,告诉你查询没有完成“好”的执行)而不是他预期的资源。

所以你必须使用类似的东西mysql_error()来检索原因并更正上面的代码。

编辑 看看你的代码,你错过了,你的order by领域

于 2012-05-22T14:52:37.750 回答
0

发生错误时,mysql_query返回布尔值 false。所以看起来你必须修复你的查询。您可以使用mysql_error找出错误是什么。

于 2012-05-22T14:55:11.043 回答
0

确保您也有一个有效的数据库连接。试试 connect_db($host, $id, $pwd, $db) 或 die(mysql_error())。另外,按照其他人的建议,在 sql 语句中使用 die。

于 2012-05-22T14:55:53.587 回答