Where Conditions

Where Conditions

michi89pafmichi89paf Posts: 5Questions: 0Answers: 0

Hello,

I have a problem with the "where condition" when outputting DataTables (Editor). After login, only data should be displayed for a group assigned to a user. There are 10 groups, but some members of staff may also see several groups.
The table looks like this:
Name, first name, address, group

For the reason I need the where condition more often on the column "group".
This condition works:
-> where ('group', $ _SESSION ['username'])

These conditions do not work (No data available in table):
-> where ('group', $ _SESSION ['username'])
-> where ('group', $ usergroup1)

Can you please help me how this works?

Thanks in advance.

Michael

Replies

  • michi89pafmichi89paf Posts: 5Questions: 0Answers: 0

    Hello again,
    you can't help me? Or is my English too bad that you don't understand what I mean?

    Michael

  • allanallan Posts: 61,891Questions: 1Answers: 10,143 Site admin
    edited March 2017

    Its more than I sometimes need a little extra time to be able to reply to as many questions as I would like to be able to do! If you post in a different category from "Free community support" that would also help me direct which threads I should give priority.

    It sounds like you need to use an OR logic combiner - the default is AND.

    Try:

    ->where( function ( $q ) use ($usergroup1) {
      $q->where('group', $ _SESSION ['username']);
      $q->or_where('group', $usergroup1);
    } )
    

    Allan

  • michi89pafmichi89paf Posts: 5Questions: 0Answers: 0

    Sorry, i understand.
    I just asked again, because it could have been that I have not expressed myself correctly.

    It works now perfectly.

    Thanks alot :-)

  • michi89pafmichi89paf Posts: 5Questions: 0Answers: 0

    Hello Allan,

    I must write again.
    The where function works.
    If I now change a record, the table does not update automatically.
    Only after updating (F5) of the page is the changed entry in the table.
    As soon as I remove the where function, a change will update immediately.

    Do you have a solution for this?

    Thanks in advance.

    Michael

  • allanallan Posts: 61,891Questions: 1Answers: 10,143 Site admin

    Could you try this:

    ->where( function ( $q ) use ($usergroup1) {
      $q->where_group( function ( $q2 ) use ($usergroup1) {
        $q2->where('group', $ _SESSION ['username']);
        $q2->or_where('group', $usergroup1);
      } );
    } )
    

    I think its the grouping that is causing the issue.

    Allan

  • michi89pafmichi89paf Posts: 5Questions: 0Answers: 0

    Thank's, it works ;)

    Michael

This discussion has been closed.