Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

NOT IN

hi


$day1 = date("m-j-y", strtotime("-7 days"));
        $day2 = date("m-j-y", strtotime("-1 days"));

         $weekvideos = Videos::find(array(
            "adddate BETWEEN :date: AND :date2:",
            'category NOT IN (5)',
            "bind" => array(
                'date' => $day1,
                'date2'=> $day2 
            ),
            "order" => "RAND()",
            "limit" => 52
        ));

'category NOT IN (5)' does not work and why?



69.5k
Accepted
answer

The first parameter of find() is the where clause. You can use 'conditions' key also. Full spec here: https://docs.phalconphp.com/en/latest/reference/models.html#finding-records

To make your query work change to:

         $weekvideos = Videos::find(array(
            "adddate BETWEEN :date: AND :date2: AND category NOT IN (5)",
            // 'category NOT IN (5)', // this belongs above
            "bind" => array(
                'date' => $day1,
                'date2'=> $day2 
            ),
            "order" => "RAND()",
            "limit" => 52
        ));

Thank u


        $day1 = date("m-j-y", strtotime("-7 days"));
        $day2 = date("m-j-y", strtotime("-1 days"));

        $categorynum = ["5"];
        $arraycatnum = array_values($categorynum);

         $weekvideos = Videos::find(array(
            "adddate BETWEEN :date: AND :date2: AND category NOT IN ({category:array})",
            "bind" => array(
                'date'  => $day1,
                'date2' => $day2,
                'category' => $arraycatnum
            ),
            "order" => "RAND()",
            "limit" => 52
        ));

The first parameter of find() is the where clause. You can use 'conditions' key also. Full spec here: https://docs.phalconphp.com/en/latest/reference/models.html#finding-records

To make your query work change to:

        $weekvideos = Videos::find(array(
           "adddate BETWEEN :date: AND :date2: AND category NOT IN (5)",
           // 'category NOT IN (5)', // this belongs above
           "bind" => array(
               'date' => $day1,
               'date2'=> $day2 
           ),
           "order" => "RAND()",
           "limit" => 52
       ));

Good job on binding array values for the IN clause.