我正在使用图表-堆积的柱状图。我试图创建一个动态查询。
$query = mysql_query("SELECT * FROM products WHERE productid IN ".$full);
这是查询,$ full定义为:
$que1 = mysql_query("SELECT productid from admin_levels WHERE level>1 AND userid=$UserID ORDER BY productid");
$op1="";
while($row1 = mysql_fetch_row($que1))
{
foreach($row1 as $cell1)
{
$op1.="'".$cell1."',";
}
}
$temp1=strlen($op1)-1;
$op1=substr($op1,0,$temp1);
$full = "( ".$op1." )";
最佳答案
您可以像这样在单个查询中调用上述查询:
$query = mysql_query("SELECT * FROM products WHERE productid IN (SELECT productid from admin_levels WHERE level>1 AND userid=$UserID ORDER BY productid)") or die(mysql_error()) ;
我建议您不要使用mysql语句,因为它们容易受到攻击。与此相反,请尝试mysqli或PDO语句