Where clause using ssp.class.php(solved)

Where clause using ssp.class.php(solved)

patopatopatopatopatopato Posts: 4Questions: 1Answers: 0

first of all sorry my english is not good enough but i wanted to share my solution with everyone i dont know if there is a better solution but im a newbbie using php and datatables, so here i go:

i was trying to populate the datatable with those rows that i wanted only
for example i have a parent datatabase table named "empresa" that has many vehicles and i created a table named vehicles to store that information. i sent the empresa id parameter to the ssp.class so i can have those rows (vehicles) that belongs only to that id parameter. the solution was adding this line of code

$data = SSP::sql_exec( $db, $bindings,
"SELECT SQL_CALC_FOUND_ROWS ".implode(", ", SSP::pluck($columns, 'db'))."
FROM $table where empresa_id= $empresa_id ///// <-------------here
$where
$order
$limit"
);

when the page was loaded i realized that i have what i wanted.i had this
no placas modelo empresa_id
4 ABCDEE JEEP CHEROKKE 4
2 TTT123 CHEVROLET 02 4

instead of this:

no placas modelo empresa_id ////total of records
1 ABCD FORD 98 3
4 ABCDEE JEEP CHEROKKE 4
2 TTT123 CHEVROLET 02 4

but the problem came when i started typing on the search box because the query had many errors sintax
the solution was to remove the line of code added and leave the original code intact like this:

// Main query to actually get the data
$data = SSP::sql_exec( $db, $bindings,
"SELECT SQL_CALC_FOUND_ROWS ".implode(", ", SSP::pluck($columns, 'db'))."
FROM $table
$where
$order
$limit"
);

so i realized that i can do this

before the execution of SSP:sql_exec happened

if ( $where == '' ) {
$where.=" where empresa_id= $empresa_id "; /// if theres no where statement i add the where statement
}
else
{
$where.=" and empresa_id= $empresa_id"; /// if where statement has something i only append the criteria

    }

    // Main query to actually get the data
    $data = SSP::sql_exec( $db, $bindings,
        "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", SSP::pluck($columns, 'db'))."`
         FROM `$table`  
         $where  
         $order
         $limit"
    );

and now everything works for me now
im very happy now lol

Replies

  • giovani07giovani07 Posts: 1Questions: 0Answers: 0

    Exactly what I needed!!
    Works for me.

    Valeu aí!

This discussion has been closed.