Editing the $sWhere w/Server Side getting no results on table?

Editing the $sWhere w/Server Side getting no results on table?

AKuehneAKuehne Posts: 5Questions: 0Answers: 0
edited July 2011 in General
I've been working on this for a few days and i'm stuck.
I get 0 results on my table when the data is in the DB. I know its a problem with my $sWhere, but i cant see a problem. Someone help me please? $_SESSION['SESS_tech_id'] is VARCHAR by the way.
[code]
$that = $_SESSION['SESS_tech_id'];
$sWhere = "";
if ( $_GET['sSearch'] != "" )
{
$sWhere = "WHERE (";
for ( $i=0 ; $i

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    I'm pretty sure in PHP, variables like $that will not be interpolated inside single quotes.

    and your database might require single quotes, not double, for it's query.

    swap the quotes . change line 11 to
    [code]
    $sWhere .= " AND skid NOT LIKE '%rtv%' AND skid NOT LIKE '%scrap%' AND vendor = '$that' )";
    [/code]
  • AKuehneAKuehne Posts: 5Questions: 0Answers: 0
    Thanks for looking it over. Actually that part was working fine.
    I'm thinking my problem is in line 13.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited July 2011
    There's no way that could be working fine. you would have had errors on this part:
    [code]
    $sWhere .= ' AND skid NOT LIKE '%rtv
    [/code]

    that would treat % like modulus operator, not part of your string

    to really see, check out the debugger for the response for that server call, or run the server call manually in a different browser window.
  • AKuehneAKuehne Posts: 5Questions: 0Answers: 0
    Well i updated it to yours. My response is
    {"sEcho":3,"iTotalRecords":"0","iTotalDisplayRecords":"0","aaData":[]}
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    another debugging tool you can use is to return your $sQuery with your JSON. it won't conflict with DataTables.

    after you craft your main query, save a copy of it, then add to the object you return
    [code]
    $sQuery = "SELECT ".str_replace(" , ", " ", implode(", ", $aColumns))."
    FROM $sTable
    $sWhere
    $sOrder
    $sLimit
    ";
    $sReturnQuery = $sQuery; // <--- new line
    [/code]

    then later return it
    [code]
    $output = array(
    "sEcho" => $sEcho,
    "iTotalRecords" => $iTotal,
    "iTotalDisplayRecords" => $iFilteredTotal,
    "sReturnQuery" => $sReturnQuery, // <--- new line
    "aaData" => array()
    );
    [/code]

    inspect the query to see if $_SESSION['SESS_tech_id'] is being read properly, for instance.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    And the fact that you are getting iTotalRecords = 0 suggests there's no data in your table.
  • AKuehneAKuehne Posts: 5Questions: 0Answers: 0
    I've changed the iTotalRecords to => $iFilteredTotal.
    I'll try the return query.
  • AKuehneAKuehne Posts: 5Questions: 0Answers: 0
    Turns out that the $_SESSION var is not being returned correctly.
    Thanks for all the help.
This discussion has been closed.