Multiple WHERE

Multiple WHERE

antoniocibantoniocib Posts: 277Questions: 62Answers: 1

Hi guys I have a problem where I am stuck, I have a query to execute the server side code is the following but I don't know how to write it in Editor can you help me?

SELECT * FROM `scrivania` 
WHERE
scarico_bo = "2020-10-06" OR delivery = "2020-10-06" 
AND
hub = 1 
OR 
hub = 0 AND start = "HUB"

This is serverside and work.

->where( function ($q) {
if (isset($_POST['startDate'])) {
    $q->where('scarico_bo', $_POST['startDate'], '=');
->or_where( function ( $r ) {
    $r->where('delivery', $_POST['startDate'], '=');
});
    $q->where( 'hub',1)
    ->or_where( function ( $r ) {
            $r->where( 'hub', 0 );
            $r->where( 'start', 'HUB' );


});
}
})

this is clientside by Editor and not work..

Answers

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    Try this - it looks like you have a few PHP syntax errors in the above code:

    ->where( function ($q) {
        if (isset($_POST['startDate'])) {
            $q
                ->where('scarico_bo', $_POST['startDate'], '=')
                ->or_where('delivery', $_POST['startDate'], '=');
        }
    
        $q
            ->where( 'hub',1)
            ->or_where( function ( $r ) {
                $r->where( 'hub', 0 );
                $r->where( 'start', 'HUB' );
    })
    

    Allan

  • antoniocibantoniocib Posts: 277Questions: 62Answers: 1

    Hello @allan thanks for the hint but it doesn't work I'll explain the criterion with which the server-side query works based on the date it also loads the other conditions, instead here it loads all the conditions that I give it in the sense, it loads me the line where hub = 1 however does not correspond with the date that was sent with "startDate", I need that based on "startDate" it finds all the data, the server-side query is right but I don't know how to write it on the client side with Editor ..

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416

    it loads me the line where hub = 1 however does not correspond with the date that was sent with "startDate",

    it does if you provide the start date

    I need that based on "startDate" it finds all the data, the server-side query is right but I don't know how to write it on the client side with Editor ..

    there are no client side queries, SQL is server side only

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    Add ->debug(true) just before the ->process(...) call. Then check the response from the server in your browser's network inspector. It will include the SQL that was generated. Perhaps you can copy and paste that here if it doesn't make sense.

    Allan

This discussion has been closed.