[英]Select from table where columns names equal data in a different table
I am running this SQL Query: 我正在运行此SQL查询:
$sql2="SELECT * from callplanmeta ";
$rs2=mysql_query($sql2,$conn) or die(mysql_error());
while($result2=mysql_fetch_array($rs2))
{
$column_list[] = $result2["callplanname"];
}
$sql="SELECT LEAST(NULLIF(".implode(',',$column_list).",0)) as num FROM callplandata ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
while($result=mysql_fetch_array($rs))
{
echo $result["description"].' - '.$result["num"].'<br><br>';
}
So in the callplanmeta table are rows with the column names for the callplandata table. 因此,在callplanmeta表中是带有callplandata表的列名称的行。
This query is working fine but I need a way to stop it from showing values that are zero from the $result["num"]
result. 该查询工作正常,但我需要一种方法来阻止它显示来自
$result["num"]
结果为零的值。 I want it to not show the zero values and just show the next one for every row. 我希望它不显示零值,而只显示每行的下一个。
You should try: 你应该试试:
$sql="SELECT LEAST(NULLIF(".implode(',',$column_list).",0)) as num FROM callplandata WHERE LEAST(NULLIF(".implode(',',$column_list).",0)) != 0";
instead of: 代替:
$sql="SELECT LEAST(NULLIF(".implode(',',$column_list).",0)) as num FROM callplandata ";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.