2013-10-08 132 views
0

大家好,我的第一個問題在這裏親切指導我我正在接收ID的變量它可能是2,3,4代表這些ID的我從數據庫中提取數據時,我直接運行查詢在DATABSE它做工精細,當我在文件中使用它僅返回第一個匹配的記錄中的所有其他左翼選擇查詢返回一個匹配的記錄

$resid在此varaibale我收到varaibles

$query_responsibilities_RS = "SELECT * FROM responsibility WHERE resID IN ($resIDs)"; 

這是我努力

$respons_RS = mysql_query($query_respons_RS, $timespace) or die(mysql_error());              
$row_respons_RS = mysql_fetch_assoc($respons_RS); 
$total_respons_RS = mysql_num_rows($respons_RS); 

$rescID = $row_respons_RS["rescID"]; here i need records but it returns one record i want to use this $rescID in second query 

$query_rescategories_RS = "SELECT * FROM responsibility_category WHERE rescID IN ($rescID)"; 
$rescategories_RS = mysql_query($query_rescategories_RS, $timespace) or die(mysql_error()); 
$row_rescategories_RS = mysql_fetch_assoc($rescategories_RS); 
$total_rescategories_RS = mysql_num_rows($rescategories_RS); 

<?php do{ 
      echo ("<h4>".addcslashes($row_rescategories_RS["rescName"],"\"")."</h4>"); 
     } while ($row_rescategories_RS = mysql_fetch_assoc($rescategories_RS)); ?> 
查詢

我使用循環,但我只得到了一個紀錄,但我有一個以上的記錄

+0

什麼是循環您嘗試?你會希望按照'while($ row = mysql_fetch_assoc($ respons_RS)){echo $ row ['rescID']; }' – SmokeyPHP

+0

雖然你不應該使用'mysql_ *' - 查看MySQLi和PDO。 'mysql_ *'已被棄用一段時間,不應該使用 – SmokeyPHP

+0

你能回顯_ $ rescID_嗎?它包含什麼價值? –

回答

1

你應該循環它 試試下面的代碼

while($row_respons_RS = mysql_fetch_assoc($respons_RS)) { 
echo $row_respons_RS['rescID']; //here you will get records 
} 
0

泰使用:

do{ 
$rescID[] = $row_respons_RS["rescID"]; 
}while ($row_respons_RS = mysql_fetch_assoc($respons_RS)); 

然後:

$query_rescategories_RS = "SELECT * FROM responsibility_category WHERE rescID IN (" . implode(",",$rescID) . ")"; 
+0

謝謝大家的幫助 –

0

刪除此lin Ë $row_rescategories_RS = mysql_fetch_assoc($rescategories_RS);

$query_rescategories_RS = "SELECT * FROM responsibility_category WHERE rescID IN ($rescID)"; 
$rescategories_RS = mysql_query($query_rescategories_RS, $timespace) or die(mysql_error()); 
$row_rescategories_RS = mysql_fetch_assoc($rescategories_RS); 
$total_rescategories_RS = mysql_num_rows($rescategories_RS); 

只應使用while循環。

這裏

<?php do{ 
      echo ("<h4>".addcslashes($row_rescategories_RS["rescName"],"\"")."</h4>"); 
     } while ($row_rescategories_RS = mysql_fetch_assoc($rescategories_RS)); ?>