Bug in the server side SQL example?
Bug in the server side SQL example?
bozden
Posts: 10Questions: 0Answers: 0
Hi,
I started to use Ajax with DT and started with the given PHP example. I have buttons on the rightmost column. So I define aColumns as:
[code]$aColumns = array( 'id', 'name', 'description', ' ');[/code]
But in this case an extra comma comes out in the SQL on this line:
[code]SELECT SQL_CALC_FOUND_ROWS `".str_replace(" , ", " ", implode("`, `", $aColumns))."`[/code]
Like:
[code]SELECT SQL_CALC_FOUND_ROWS id, name, description, FROM ... [/code]
I added the following code to correct the issue:
[code]
/* SQL queries - Get data to display */
$sColumns = trim(str_replace(" , ", " ", implode(", ", $aColumns)));
if (substr($sColumns, -1) == ',') {
$sColumns = substr($sColumns, 0, strlen($sColumns)-1);
}
$q = "SELECT SQL_CALC_FOUND_ROWS ". $sColumns ." FROM $sTable $sWhere $sOrder $sLimit ";
$rResult = mysqli_query($db, $q) or die(mysqli_error($db));
[/code]
I started to use Ajax with DT and started with the given PHP example. I have buttons on the rightmost column. So I define aColumns as:
[code]$aColumns = array( 'id', 'name', 'description', ' ');[/code]
But in this case an extra comma comes out in the SQL on this line:
[code]SELECT SQL_CALC_FOUND_ROWS `".str_replace(" , ", " ", implode("`, `", $aColumns))."`[/code]
Like:
[code]SELECT SQL_CALC_FOUND_ROWS id, name, description, FROM ... [/code]
I added the following code to correct the issue:
[code]
/* SQL queries - Get data to display */
$sColumns = trim(str_replace(" , ", " ", implode(", ", $aColumns)));
if (substr($sColumns, -1) == ',') {
$sColumns = substr($sColumns, 0, strlen($sColumns)-1);
}
$q = "SELECT SQL_CALC_FOUND_ROWS ". $sColumns ." FROM $sTable $sWhere $sOrder $sLimit ";
$rResult = mysqli_query($db, $q) or die(mysqli_error($db));
[/code]
This discussion has been closed.
Replies
However, the script is intended as a starting point, so its good to hear you've got a work around for your extension to it!
Allan