Display Only A Partial List From DB

Display Only A Partial List From DB

ExviterminiExvitermini Posts: 7Questions: 0Answers: 0
edited September 2011 in General
I have the datatable working but server_process.php lists everything in the database table. I want to display only a partial list from the database table. For example, how can I do the equivalent of SQL would be SELECT * FROM tblStuff WHERE member_id=2? I need to incorporate the "WHERE" part into the data retrieved from server_process.php. I am dealing with multiple users so other users should not be able to see data in the table that doesn't belong to them.

I figured out that if a user is to do a search in the table, server_processing.php adds the WHERE clause. I want to be able to add WHERE clause for the full data retrieved so other data that doesnt comply with WHERE clause is not returned.

Anyone have any idea how I can achieve this?

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited December 2011
    how are you tracking sessions/user logins? you can pass some token (or user id) into your server_processing script and then add to the WHERE clause for member_id

    the preferred way to add params to the server_processing call is to push params onto aoData in fnServerData

    [code]
    /* POST data to server */
    $(document).ready(function() {
    $('#example').dataTable( {
    "sAjaxSource": "data_source.php",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    /* Add some data to send to the source */
    aoData.push( { "name": "member_id", "value": $_SESSION["member_id"] } );
    $.ajax( {
    "dataType": 'json',
    "url": sSource,
    "data": aoData,
    "success": fnCallback
    } );
    }
    } );
    } );
    [/code]

    of course on the server side look for $_GET["member_id"] (or $_REQUEST["member_id"]) and amend the WHERE clause
  • ExviterminiExvitermini Posts: 7Questions: 0Answers: 0
    Oh sick!! That works like a charm. Thanks very much. I was doing it wrong before. :)
  • grsgrs Posts: 2Questions: 0Answers: 0
    Im using MVC 3 and I am trying to "catch" the parameters passed by fnServerParams on the controller action which has a method signature like so: [code] public ActionResult GetDailyRateBillingRows(jQueryDataTableParamModel param)[/code]. How do I access the parameters on the server side?
This discussion has been closed.