English 中文(简体)
不存在 - MysQL/PHP [复制]
原标题:WHERE NOT EXISTS - MYSQL/PHP [duplicate]

我无法让我的无名小卒 Mysql 声明 工作, 它快把我逼疯了:

$ancestors = mysql_query( 
    SELECT * FROM comments e
        WHERE 
            ancestors = "  . $comment["id"] .  " AND 
            user_id != "  . $user->user_object["id"] .  " AND
                NOT EXISTS
                    (
                        SELECT  null 
                        FROM    notifications d
                        WHERE   d.target_id = e.id
                    )
 , $database->connection_handle);

有什么想法吗?

错误:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /<>/<>/functions.php on line 785
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /<>/<>/functions.php on line 785
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /<>/<>/functions.php on line 785
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /<>/<>/functions.php on line 785
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /<>/<>/functions.php on line 785
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /<>/<>/functions.php on line 785
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /<>/<>/functions.php on line 785
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /<>/<>/functions.php on line 785
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /<>/<>/functions.php on line 785

第785行:

    while($reply = mysql_fetch_array($ancestors, MYSQL_ASSOC)){

如果我这样做:

$ancestors = mysql_query( SELECT * FROM   . $database->db_prefix .  comments 
    WHERE    
        ancestors = "  . $comment["id"] .  " AND 
        user_id != "  . $user->user_object["id"] .  " , 
        $database->connection_handle
);

它返回我预期的结果。

通知表是否包含一个条目

i>==================================================================================================================

string(46) "Table  whatever_co.comments  doesn t exist"

//SOLVED::: . $database->db_prefix . was missing from my table selectors.

最佳回答

我错过了我的表格前缀 : $database- & gt; db_ prefix. from comments and notice. 我错过了表格前缀 : $database- & gt; db_ prefix. from compublications and not understand. 。 之所以出现这个问题,是因为我第一次没有使用..., 并且假设那部分是不正确的。 感谢您一直以来的感谢。 这是庆祝的原因 。

问题回答

您的 < code> NOT exists 是好的。 我认为这与您的选择可能有问题。 您在该表格中是否有名为“ null” 的字段? 如果不是, 您的问题所在 。

我想你正在寻找的东西 类似于

Select * 
FROM notifications d
WHERE d.target_id = e.id
AND e.id IS NULL

尝试使用类似的东西。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签