Adding a "Where" clause in PHP query

Adding a "Where" clause in PHP query

studio6000studio6000 Posts: 7Questions: 0Answers: 0
edited March 2011 in General
Hi,

I installed the server side example and that is working fine. See here:

http://frumtown.com/listings/server_side.php

I want to filter the MySQL in the server_processing.php script . I managed to do that by adding:

AND custom_7 = 2

to the $where variable.

However, when I change that to

AND custom_7 = " . $_GET['custom_7']

and then go to http://frumtown.com/listings/server_side.php?custom_7=2

It doesn't work.

So I tried the custom_vars script as well thinking that would work, but it doesn't either.

I added this
aoData.push( { "name": "custom_7", "value": "2" } );

What am I doing wrong? I need to be able to control the MySQL query since users will be searching by a form and non-relevant rows should not appear.

Hope this all makes sense.

Thanks in advance for any help you can give.
Michelle

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Hi Michelle,

    You need to do what you are currently doing with the aoData.push (like in this example: http://datatables.net/examples/server_side/custom_vars.html ). However at the moment you have an SQL error:

    [code]
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id
    asc
    LIMIT 0, 10' at line 4
    [/code]
    Might be worth printing out your generated SQL statement and see where it is going wrong.

    Allan
  • studio6000studio6000 Posts: 7Questions: 0Answers: 0
    I reinstalled everything as the original with the same exact data you used. I created a new test database with the ajax table. That all works fine. However, when I add this

    [code]
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    /* Add some extra data to the sender */
    aoData.push( { "name": "grade", "value": "C" } );
    $.getJSON( sSource, aoData, function (json) {
    /* Do whatever additional processing you want on the callback, then tell DataTables */
    fnCallback(json)
    } );
    }
    [/code]

    It still doesn't work. It shows all 57 when it should only show about 8.

    Please see my example here: http://frumtown.com/listings/server_side.html
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Looks okay to me on load (I'm using Chrome). I load the page and it's got 10 rows showing. Maybe a cache issue?

    Allan
  • studio6000studio6000 Posts: 7Questions: 0Answers: 0
    I'm confused. How are you only seeing 10 Rows. I tried in Mozilla and Chrome. All 57 are showing.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    I'm also only seeing 10 rows. and changing the drop down list with Length values changes the number of rows to that value. http://i.imgur.com/g7KaN.png

    note: I'm seeing 2 sets of DOM elements. the top one doesn't work, the bottom one does. are you intiailizing the table more than once?
  • macnoobstermacnoobster Posts: 1Questions: 0Answers: 0
    Hi, i think i understand what Studio 6000 meant,

    He wants a pre-filter before the 'live' filtering , so that for example : blahblah.php?custom_7=Gecko only returns gecko browsers, and then the user could filter it a little more by version and so on..

    I wanted to do the same but i can't find the solution, have you Studio 6000?
This discussion has been closed.