Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正在寻找从select语句的后半部分排除select语句变量的方法_Php_Sql_Arrays - Fatal编程技术网

Php 正在寻找从select语句的后半部分排除select语句变量的方法

Php 正在寻找从select语句的后半部分排除select语句变量的方法,php,sql,arrays,Php,Sql,Arrays,我正在寻找一种方法,从数据库中选择前三名中的用户,然后选择前五名,包括前三名,不包括以前选择的前三名。代码如下: $strSQL=“从“.USERS\u TABLE.”ut“.USER\u MATCH\u TABLE.”umt中选择id WHERE“.内爆('AND',$WHERE)。“和ut.id=umt.id\u用户和(ut.a a=“'a1”或ut.b=“'AA1”或ut.a=“'a1”或ut.d=“'d1”或ut.e=“'1”或ut.a=“'a1”或“a.a”或“a.a”或“a.a”或“

我正在寻找一种方法,从数据库中选择前三名中的用户,然后选择前五名,包括前三名,不包括以前选择的前三名。代码如下:

$strSQL=“从“.USERS\u TABLE.”ut“.USER\u MATCH\u TABLE.”umt中选择id WHERE“.内爆('AND',$WHERE)。“和ut.id=umt.id\u用户和(ut.a a=“'a1”或ut.b=“'AA1”或ut.a=“'a1”或ut.d=“'d1”或ut.e=“'1”或ut.a=“'a1”或“a.a”或“a.a”或“a.a”或“a.a”或“a.a”或“a.a”或“a.a”或“a.a”或“a”或“a.a”或“a”或ut.a.a”或“1”或“1”或“1”或ut.e=“'或“1”或“1”或“1”或“1”或“1”或“1.f”或“1”或“1”或“1”或“1”或“1”或“1”或“1”或“1.g”或“1”或“1.g或“1”或“1”或“1”或“或“u1'或ut.v='$v1'或ut.w='$w1'或ut.x='$x1'或ut.y='$y1'oR ut.z='$z1'或ut.aa='$aa1'或ut.ab='$ab1'或ut.ac='$ac1'或ut.ad='$ad1'或ut.ae='$ae1'或ut.af='$af1'或ut.ag='$ag1'或ut.ah='$ah1'),以及(ut.a a=“'a 2”或ut.b=“'a 2”或ut.a.a=“'a 2”或ut.d=“'d2”或ut.e=“'2”或ut.a.a=“'a 2”或“a.a”或“a.a”或“a.a”或b.b.a=“'a.a.a.a a a=“'a.a”或“2”或“2”或“2”或“2”或“2”或“b.a.a”或“2”或“2”或“a.a.a”或“2”或“2”或“a.a.a”或“2”或“2”或“或“或ut.b.a.a或“或“或“或b”或“a.a.a.a.a”或“2”或“2”或“或“或“或b.a.a.a.a”或或u2'或ut.v='$v2'或ut.w='$w2'或ut.x='$x2'或ut.y='$y2'o“z2”或ut.ab2”或ut.ac=“$ac2”或ut.ac=“$ac2”或ut.ac=“$ac2”或ut.ad=“$ad2”或ut.AZ=“$z2”或ut.z=“$z2”或ut.A2”或ut.AAAAAa=“$z2”或A2”或A2”或ut.A2”或ut.A2”或ut.AAAA2”或ut.aa2”或AAAAAA2”或ut.AAAAAAAAAAAAAAAAAAAAAa=“或AAAAAAAAAAAAAAAAAa=“或AAAAAAAAAAAAAAAAAAAAAAAAAa=“或AAAAAAAAAAAA或ut.l='$l1'或ut.m='$m1'或ut.n='$n1'或ut.o='$o1'或ut.p='$p1'或ut.q='$q1'或ut.r='$r1'或ut.s='$s1'或ut.t='$t1'或ut.u='$u1'或ut.v='$v1'或ut.w='$w1'或ut.x='$x1'或ut.y='$y1'或ut.z='$z1'或ut.aa='$aa1'或ut.ab='$ab1'或ut.ac='$ac1'或ut.ad='$ad1'或ut.ae='$AFUT''; $rs=$dbconn->Execute($strSQL)


查询的第一组是AND(ut.a='$a1'等)第二部分在和之后,包括前三、第四和第五部分的第一部分。我想从前五名中列出前三名中包含的任何内容。有什么想法吗?我想到了数组,但复杂性超出了我的能力范围。提前谢谢你,以我的生命计,我无法理解你的查询在做什么,但是你的方式解决您所问的一般问题的方法是:两个有2个查询,并合并结果。可能类似于:

SELECT id
FROM ".USERS_TABLE." ut,
    ".USER_MATCH_TABLE." umt
WHERE ".implode(' AND ', $where). "
    AND ut.id = umt.id_user
    AND (
        ut.a = '$a1'
        OR ut.b = '$b1'
        OR ut.c = '$c1'
        OR ut.d = '$d1'
        OR ut.e = '$e1'
        OR ut.f = '$f1'
        OR ut.g = '$g1'
        OR ut.h = '$h1'
        OR ut.i = '$i1'
        OR ut.j = '$j1'
        OR ut.k = '$k1'
        OR ut.l = '$l1'
        OR ut.m = '$m1'
        OR ut.n = '$n1'
        OR ut.o = '$o1'
        OR ut.p = '$p1'
        OR ut.q = '$q1'
        OR ut.r = '$r1'
        OR ut.s = '$s1'
        OR ut.t = '$t1'
        OR ut.u = '$u1'
        OR ut.v = '$v1'
        OR ut.w = '$w1'
        OR ut.x = '$x1'
        OR ut.y = '$y1'
        OR ut.z = '$z1'
        OR ut.aa = '$aa1'
        OR ut.ab = '$ab1'
        OR ut.ac = '$ac1'
        OR ut.ad = '$ad1'
        OR ut.ae = '$ae1'
        OR ut.af = '$af1'
        OR ut.ag = '$ag1'
        OR ut.ah = '$ah1'
        )
UNION ALL
SELECT id
FROM ".USERS_TABLE." ut,
    ".USER_MATCH_TABLE." umt
WHERE ".implode(' AND ', $where). "
    AND ut.id = umt.id_user
    AND(
        ut.a = '$a2'
        OR ut.b = '$b2'
        OR ut.c = '$c2'
        OR ut.d = '$d2'
        OR ut.e = '$e2'
        OR ut.f = '$f2'
        OR ut.g = '$g2'
        OR ut.h = '$h2'
        OR ut.i = '$i2'
        OR ut.j = '$j2'
        OR ut.k = '$k2'
        OR ut.l = '$l2'
        OR ut.m = '$m2'
        OR ut.n = '$n2'
        OR ut.o = '$o2'
        OR ut.p = '$p2'
        OR ut.q = '$q2'
        OR ut.r = '$r2'
        OR ut.s = '$s2'
        OR ut.t = '$t2'
        OR ut.u = '$u2'
        OR ut.v = '$v2'
        OR ut.w = '$w2'
        OR ut.x = '$x2'
        OR ut.y = '$y2'
        OR ut.z = '$z2'
        OR ut.aa = '$aa2'
        OR ut.ab = '$ab2'
        OR ut.ac = '$ac2'
        OR ut.ad = '$ad2'
        OR ut.ae = '$ae2'
        OR ut.af = '$af2'
        OR ut.ag = '$ag2'
        OR ut.ah = '$ah2'
        OR ut.a = '$a1'
        OR ut.b = '$b1'
        OR ut.c = '$c1'
        OR ut.d = '$d1'
        OR ut.e = '$e1'
        OR ut.f = '$f1'
        OR ut.g = '$g1'
        OR ut.h = '$h1'
        OR ut.i = '$i1'
        OR ut.j = '$j1'
        OR ut.k = '$k1'
        OR ut.l = '$l1'
        OR ut.m = '$m1'
        OR ut.n = '$n1'
        OR ut.o = '$o1'
        OR ut.p = '$p1'
        OR ut.q = '$q1'
        OR ut.r = '$r1'
        OR ut.s = '$s1'
        OR ut.t = '$t1'
        OR ut.u = '$u1'
        OR ut.v = '$v1'
        OR ut.w = '$w1'
        OR ut.x = '$x1'
        OR ut.y = '$y1'
        OR ut.z = '$z1'
        OR ut.aa = '$aa1'
        OR ut.ab = '$ab1'
        OR ut.ac = '$ac1'
        OR ut.ad = '$ad1'
        OR ut.ae = '$ae1'
        OR ut.af = '$af1'
        OR ut.ag = '$ag1'
        OR ut.ah = '$ah1'
        )
SELECT id
FROM ".USERS_TABLE." ut,
    ".USER_MATCH_TABLE." umt
WHERE ".implode(' AND ', $where). "
    AND ut.id = umt.id_user
    AND (
        ut.a = '$a1'
        OR ut.b = '$b1'
        OR ut.c = '$c1'
        OR ut.d = '$d1'
        OR ut.e = '$e1'
        OR ut.f = '$f1'
        OR ut.g = '$g1'
        OR ut.h = '$h1'
        OR ut.i = '$i1'
        OR ut.j = '$j1'
        OR ut.k = '$k1'
        OR ut.l = '$l1'
        OR ut.m = '$m1'
        OR ut.n = '$n1'
        OR ut.o = '$o1'
        OR ut.p = '$p1'
        OR ut.q = '$q1'
        OR ut.r = '$r1'
        OR ut.s = '$s1'
        OR ut.t = '$t1'
        OR ut.u = '$u1'
        OR ut.v = '$v1'
        OR ut.w = '$w1'
        OR ut.x = '$x1'
        OR ut.y = '$y1'
        OR ut.z = '$z1'
        OR ut.aa = '$aa1'
        OR ut.ab = '$ab1'
        OR ut.ac = '$ac1'
        OR ut.ad = '$ad1'
        OR ut.ae = '$ae1'
        OR ut.af = '$af1'
        OR ut.ag = '$ag1'
        OR ut.ah = '$ah1'
        )
UNION ALL
SELECT id
FROM ".USERS_TABLE." ut,
    ".USER_MATCH_TABLE." umt
WHERE ".implode(' AND ', $where). "
    AND ut.id = umt.id_user
    AND(
        ut.a = '$a2'
        OR ut.b = '$b2'
        OR ut.c = '$c2'
        OR ut.d = '$d2'
        OR ut.e = '$e2'
        OR ut.f = '$f2'
        OR ut.g = '$g2'
        OR ut.h = '$h2'
        OR ut.i = '$i2'
        OR ut.j = '$j2'
        OR ut.k = '$k2'
        OR ut.l = '$l2'
        OR ut.m = '$m2'
        OR ut.n = '$n2'
        OR ut.o = '$o2'
        OR ut.p = '$p2'
        OR ut.q = '$q2'
        OR ut.r = '$r2'
        OR ut.s = '$s2'
        OR ut.t = '$t2'
        OR ut.u = '$u2'
        OR ut.v = '$v2'
        OR ut.w = '$w2'
        OR ut.x = '$x2'
        OR ut.y = '$y2'
        OR ut.z = '$z2'
        OR ut.aa = '$aa2'
        OR ut.ab = '$ab2'
        OR ut.ac = '$ac2'
        OR ut.ad = '$ad2'
        OR ut.ae = '$ae2'
        OR ut.af = '$af2'
        OR ut.ag = '$ag2'
        OR ut.ah = '$ah2'
        OR ut.a = '$a1'
        OR ut.b = '$b1'
        OR ut.c = '$c1'
        OR ut.d = '$d1'
        OR ut.e = '$e1'
        OR ut.f = '$f1'
        OR ut.g = '$g1'
        OR ut.h = '$h1'
        OR ut.i = '$i1'
        OR ut.j = '$j1'
        OR ut.k = '$k1'
        OR ut.l = '$l1'
        OR ut.m = '$m1'
        OR ut.n = '$n1'
        OR ut.o = '$o1'
        OR ut.p = '$p1'
        OR ut.q = '$q1'
        OR ut.r = '$r1'
        OR ut.s = '$s1'
        OR ut.t = '$t1'
        OR ut.u = '$u1'
        OR ut.v = '$v1'
        OR ut.w = '$w1'
        OR ut.x = '$x1'
        OR ut.y = '$y1'
        OR ut.z = '$z1'
        OR ut.aa = '$aa1'
        OR ut.ab = '$ab1'
        OR ut.ac = '$ac1'
        OR ut.ad = '$ad1'
        OR ut.ae = '$ae1'
        OR ut.af = '$af1'
        OR ut.ag = '$ag1'
        OR ut.ah = '$ah1'
        )