doq91130 2013-08-20 14:25
浏览 41
已采纳

从表中选择列名称与另一个表中的数据相等

I am running this SQL Query:

$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.

This query is working fine but I need a way to stop it from showing values that are zero from the $result["num"] result. I want it to not show the zero values and just show the next one for every row.

  • 写回答

1条回答 默认 最新

  • doubinchou4219 2013-08-20 14:29
    关注

    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 ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程