2011-07-19 46 views
0

需要此错误的帮助。 看不到有什么问题。mysql_query()期望参数

错误:

Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\pm website\php\bulletin_board\bulletin_board.php on line 48 

代码:

<?php 
$con = mysql_connect("localhost","root",""); //Databse connection 
if(!$con) 
{ 
    die ('Could not connect to DB' . mysql_error()); //Error promt 
} 
mysql_select_db("profound_master", $con); //Selecting the DB 
$view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC"); //Selecting the table from the DB 

if (!mysql_query ($view, $con)) 
    { 
     die ('Error Sir' . mysql_error()); //Error promt 
    } 
while ($row = mysql_fetch_array($view)) 

echo "<table width=\"1000\">"; 
echo "<tr id=\"boardLetter\">"; 
echo "<th width=\"46\">".$row['pro_no']."</th>"; 
echo "<th width=\"56\">".$row['date']."</th>"; 
echo "<th width=\"138\">".$row['project']."</th>"; 
echo "<th width=\"138\">".$row['task']."</th>"; 
echo "<th>".$row['originated']."</th>"; 
echo "<th>".$row['incharge']."</th>"; 
echo "<th>".$row['deadline']."</th>"; 
echo "<th width=\"139\">".$row['status']."</th>"; 
echo "<th width=\"151\">".$row['comment']."</th>"; 
echo "<th>".$row['din']."</th>"; 
echo "</tr>"; 
echo "</table>"; 
?> 

回答

0

无法查询您的查询结果。试试这个

$view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC"); //Selecting the table from the DB 

if (!$result) 

它应该做的魔力

+0

非常感谢你先生,错误消失了!跟进先生问题先生。我看不到任何东西。该表必须与来自数据库的数据一起出来。 :( –

+0

非常感谢您的先生。现在我解决了这个问题。 –

1

你写这样的:

$view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC"); //Selecting the table from the DB 
if (!mysql_query ($view, $con)) 

注意如何执行查询,其结果是资源分配给$view,然后尝试运行另一个查询与$view作为SQL?但$view不是SQL,它是一个结果资源,因此是错误。

就这样写:

$view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC"); 
if (!$view) 
0

你确实有两个查询。第二个查询在if语句中执行:

if (!mysql_query ($view, $con)) 

请注意,这里的$ view是类型资源,而不是字符串类型。如果你想检查查询执行正确,只需写:

if(!$view) 
+0

感谢您的帮助。:) –