Filter server side processing with $_SESSION['user_id']

Filter server side processing with $_SESSION['user_id']

upshireupshire Posts: 13Questions: 0Answers: 0
edited March 2013 in General
Hi
Can anyone point me in the direction of a straight forward example, showing how to filter the data returned from "server_processing.php". I want to limit the data returned to match the user_id to whom it belongs to. I have had a good look through this forum, however, a solution seems to evade me.
David
P.S
Because I am still in the stage of figuring out where to start, I am unable to post any code or work in process examples.

Replies

  • essexstephessexsteph Posts: 57Questions: 0Answers: 0
    I would suggest that in your your server-side script you use session_start() so you can access the user_id and then you use it in your sql query when you get your data.

    In Allan's example code look for where $sWhere is set and add it in there.

    Steph
  • upshireupshire Posts: 13Questions: 0Answers: 0
    Steph
    First off, thank you for your reply, I have opted to use the mysqli version of the server_process.php script. I have commented out the SELECT string and replaced with my own for now
    //$sQuery = "
    // SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", $aQueryColumns)."`
    // FROM `".$sTable."`".$sWhere.$sOrder.$sLimit;

    $sQuery = "SELECT * FROM acc_customers WHERE company_id = '$comp_id'";
    Only problem is that any of the associated table filters, record pageing etc no longer work as they require the variables $table,$swhere $order etc to work.

    Have you any experience in replacing the SELECT string?

    David
  • essexstephessexsteph Posts: 57Questions: 0Answers: 0
    I don't use the mysqli version but presume it's similar. I suggested in my post above you used the $sWhere variable - that way you don't have to change the select statement at all and therefore don't loose the filters, paging etc.

    My code to change $sWhere goes after Allan's and is as follows:

    [code]
    if ($extraqu <> '') {
    if ($sWhere == '')
    $sWhere = "WHERE ".$extraqu.' ';
    else
    $sWhere .= ' AND '.$extraqu.' ';
    }
    [/code]

    I set $extraqu further up if required and is the extra query I need, I presume your code would be

    [code]
    if ($sWhere == '')
    $sWhere = "WHERE company_id = '$comp_id' ";
    else
    $sWhere .= " AND company_id = '$comp_id' ";
    [/code]

    Steph
  • upshireupshire Posts: 13Questions: 0Answers: 0
    Hi Steph
    Thank's for that, I managed to get it working with the mysqli extension.Apologies for my late reply, however I have been without broadband for the past two days.

    Again
    Thank you
    David
This discussion has been closed.