dongxinxin7809 2011-10-07 08:57
浏览 39
已采纳

MySql选择Where或Where not ......而其他许多“Ands”和“Ors”

What am I doing wrong?

I want to select Churches that are Catholic Only but it is selecting more. Is it because of the Zips? they work great.

$Zips = array(60618,60625,60647,60641,60613,60657,60640,60659,60614,60639,60622,60630,60660,60651,60642,60645,60712,60612,60646,60624,60610,60626,60674,60654,60661,60644,60634,60606,60607,60707,60302,60611,60202,60602,60601,60706,60303,60603,60604,60301,60701,60656,60076,60204,60209,60304,60077,60623,60608,60305,60203,60605,60631,60664,60668,60669,60670,60673,60675,60677,60678,60680,60681,60684,60685,60686,60687,60688,60690,60691,60693,60694,60696,60697,60699,60689,60695,60171,60201,60682,60208,60053,60804,60714,60616,60130,60161,60153,60176,60068,60160,60029,60141,60091,60402,60632,60131,60290,60165,60609,60043,60164,60546);
$ZipCount = count($Zips);

for ($i = 0; $ZipCount > $i; $i++) {
    if ($i == 0) {
        $TheZips = "Zip LIKE '%$Zips[$i]%'";
    }
    else {
        $TheZips .= "OR Zip LIKE '%$Zips[$i]%'";
    }
}

$sql = mysql_query("SELECT DISTINCT * FROM info WHERE Catholic and '%true%' OR $TheZips");
$result = mysql_num_rows($sql);
  • 写回答

2条回答 默认 最新

  • doumen5491 2011-10-07 09:03
    关注
    $str_zips = implode(', ', $Zips);
    
    $sql = 
    mysql_query("SELECT DISTINCT * FROM info WHERE Catholic=true AND Zip IN ({$str_zips})");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?