2011-07-19 44 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

感謝您的幫助。:) –