2011-05-31 66 views
0

我想從我的表中檢索一些數據只是由於某種原因,我不能讓它返回任何東西。MySQL查詢不打印出數據

<?php 

$curr_uemail = mysql_query("select * from produgg_users where produgg_users.id = ".$usersClass->userID().") or die(mysql_error())");  

$arr_uemail = mysql_fetch_array($data); 

while($arr_uemail = mysql_fetch_array($data)) 
{ 
echo $arr_uemail['email']; 
} 

/*For Debugging purposes 
echo $usersClass->userID();*/ 

?> 

有人可以看到我的語法有什麼問題嗎?

+4

這是什麼? '「)或死(哎呀)」);'你沒有注意到奇怪的突出顯示? x) – reeaal 2011-05-31 21:05:35

+0

哈哈對不起,我沒有,固定它的方式仍然不工作 – Liam 2011-05-31 21:06:50

+0

所以更新您的代碼。其他代碼應該可以工作。 – reeaal 2011-05-31 21:07:55

回答

1

有很多錯誤。

首先是

$curr_uemail = mysql_query("select * from produgg_users where produgg_users.id = ".$usersClass->userID()) or die(whoops); 

第二,你不應該叫mysql_fetch_assoc而在此之前,因爲如果結果只包含一個記錄它永遠不會在同時

最後的代碼是進入:

$curr_uemail = mysql_query("select * from produgg_users where produgg_users.id = ".$usersClass->userID()) or die('whoops'); 

while($arr_uemail = mysql_fetch_array($curr_uemail)) { 
echo $arr_uemail['email']; 
} 

如前所述通過馬克如果y你只有一個記錄比這可能成爲:

$curr_uemail = mysql_query("select * from [etc]") or die('whoops');  
$arr_uemail = mysql_fetch_array($curr_uemail); 
echo $arr_uemail['email']; 
+0

對不起,我修改了我原來的問題。 – Liam 2011-05-31 21:08:28

+0

@liam你仍然有第二個錯誤閱讀我的答案 – dynamic 2011-05-31 21:09:05

+0

仍似乎沒有工作 – Liam 2011-05-31 21:12:55

0

我告訴過你的第一個錯誤通過我的評論。 但請啓用錯誤處理並執行解釋器會告訴你的內容。

error_reporting(E_ALL); 
ini_set('display_errors', 1); 

什麼也可能是錯誤的,是這樣的說法在這裏:

while($arr_uemail = mysql_fetch_array($data)) 

你應該用括號括起來或解釋可能會向您發出警告。

while(($arr_uemail = mysql_fetch_array($data))) 
+0

額外的括號沒用。省略它們不會導致警告/錯誤。 – 2011-05-31 21:46:09

+0

不,它可能會導致警告,請參閱:http://stackoverflow.com/questions/718415/warning-assignment-in-condition – reeaal 2011-05-31 22:03:33