Comparing two database variables at Server side script

Comparing two database variables at Server side script

shatrughanshatrughan Posts: 87Questions: 16Answers: 0
edited October 2023 in Editor

Hi, I'm stuck comparing two database variables using server php file as detailed below :

```Editor::inst( $db, 'Road_Movement' )->where( function ( $q ) use ( $Party_Code) {
            $q->where( 'Party_Code', $Party_Code );
            $q->where( 'Total_Amount','Final_Balance','=');
            } )```

But, it does not give the expected result.

Please suggest how to tackle this issue.

Thanks & Regards
Shatrughan

This question has accepted answers - jump to:

Answers

  • rf1234rf1234 Posts: 2,809Questions: 85Answers: 406

    What does it produce? And what is the expected result? Can you post the SQL that would produce the expected result?

  • shatrughanshatrughan Posts: 87Questions: 16Answers: 0

    Given the Total_Amount and Final_Balance be two column of database but upon comparison, nothing returns in json as reflected in attached snip.

    Whereas there are such 35 records meeting the said condition. The following snap substantiate the same

    The actual mysql query to produce the desired results is

    SELECT * FROM `Road_Movement` where Party_Code='TC1100' AND Total_Amount=Final_Balance;

    Please help to resolve the matter in question as to how we compare two database columns to filter the expected records.

    Thanks
    Shatrughan

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Can you add ->debug(true) just before the ->process(...) call please? Then shown me the JSON that the server is returning.

    Thanks,
    Allan

  • rf1234rf1234 Posts: 2,809Questions: 85Answers: 406
    edited October 2023 Answer ✓

    Try this please

    Editor::inst( $db, 'Road_Movement' )->where( function ( $q ) use ( $Party_Code) {
                $q->where( 'Party_Code', $Party_Code );
                $q->where( 'Total_Amount','Final_Balance','=', false );
                } )
    

    "Final_Balance" is not a variable that needs to be bound but it is a table column. Hence you would need to add "false".

    https://editor.datatables.net/manual/php/conditions

  • shatrughanshatrughan Posts: 87Questions: 16Answers: 0
    edited October 2023

    Thanks.

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    Doh - thanks @rf1234! I missed that Final_Balance was a column, not a string!

    Allan

Sign In or Register to comment.