Php 选择查询返回一条匹配记录

Php 选择查询返回一条匹配记录,php,mysql,Php,Mysql,大家好,这里是我的第一个问题,请指导我,我正在接收变量中的id,可能是2,3,4,代表这些id,我正在从数据库中获取数据,当我直接在数据库中运行查询时,它工作正常,当我在文件中使用时,它只返回第一个匹配的记录所有其他 $resid在此变量中,我接收变量 $query_responsibilities_RS = "SELECT * FROM responsibility WHERE resID IN ($resIDs)"; 这就是我正在尝试的问题 $respons_RS = mysql_que

大家好,这里是我的第一个问题,请指导我,我正在接收变量中的id,可能是2,3,4,代表这些id,我正在从数据库中获取数据,当我直接在数据库中运行查询时,它工作正常,当我在文件中使用时,它只返回第一个匹配的记录所有其他

$resid
在此变量中,我接收变量

$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)); ?>
$response\u RS=mysql\u query($query\u response\u RS,$timespace)或die(mysql\u error());
$row\u response\u RS=mysql\u fetch\u assoc($response\u RS);
$total_response_RS=mysql_num_行($response_RS);
$RECUSD=$row_响应[“RECUSD”];这里我需要记录,但它返回一条记录,我想在第二次查询中使用这个$RECUSIDE
$query\u rescategories\u RS=“从($rescred)”中撤销的责任类别中选择*;
$rescategories\u RS=mysql\u query($query\u rescategories\u RS,$timespace)或die(mysql\u error());
$row\u rescategories\u RS=mysql\u fetch\u assoc($rescategories\u RS);
$total_rescategories_RS=mysql_num_行($rescategories_RS);
我使用循环,但我只得到一条记录,但我有多条记录

您应该循环它 请尝试以下代码

while($row_respons_RS = mysql_fetch_assoc($respons_RS)) {
 echo $row_respons_RS['rescID'];  //here you will get records 
}
要使用的名称:

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) . ")";
删除此行
$row\u rescategories\u RS=mysql\u fetch\u assoc($rescategories\u RS)

它应该只在while循环中使用

这里



您尝试的循环是什么?您将需要按照
的思路做一些事情,而($row=mysql\u fetch\u assoc($response\u RS)){echo$row['rescID'];}
,尽管您不应该使用
mysql\uquot.
,但请查看MySQLi和PDO
mysql_*
已经有一段时间被弃用了,不应该被使用。您可以取消$echo吗?它包含什么值?将回音放在while循环之后
$query\u response\u RS
应该是
$query\u responsibility\u 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);
<?php do{ 
          echo ("<h4>".addcslashes($row_rescategories_RS["rescName"],"\"")."</h4>");
        } while ($row_rescategories_RS = mysql_fetch_assoc($rescategories_RS)); ?>