single query
类似的Tr ,
$result = mysql_query('SELECT * FROM WebProducts WHERE WebProducts.stockcode IN
(SELECT stockcode FROM news_related WHERE news = "'.$news_id.'"
AND WebProducts.visible="Y")');
从你的方法来看,它应该是,
$arrStock=array();
while($rows = mysql_fetch_array($result))
{
$arrStock[]=$rows['stockcode'];
}
if(!empty($arrStock))
{
$also_result=mysql_query("SELECT * FROM WebProducts WHERE WebProducts.stockcode
IN (".implode(',',$arrStock)." AND WebProducts.visible='Y'");
}
你知道second parameter
在mysql_query()中connection identifier
,在你的情况下,two databases
你应该有2 connections
喜欢$con1
和$con2
$result = mysql_query('SELECT * FROM WebProducts WHERE WebProducts.stockcode IN
(SELECT stockcode FROM news_related WHERE news = "'.$news_id.'"
AND WebProducts.visible="Y")',$con1);// use $con1 for first db
在第二个查询中
$also_result=mysql_query("SELECT * FROM WebProducts WHERE WebProducts.stockcode
IN (".implode(',',$arrStock)." AND WebProducts.visible='Y'",$con2);
// use $con2 for second db
mysql_也将deprecated
在PHP中删除upcoming versions
,因此请使用mysqli_*