complex SQL in server processing script?
complex SQL in server processing script?
hello all. I have a nicely working datatable, but i want to make the dataset that is used more precise, and to do that i need some fancy SQL. However, the standard serverProcessing.php that comes as an example with datatables seems hardwired to expect certain things like WHERE statements. Only problem with that is that I need to use some fancier sql that doesn't use a WHERE statement. spceifically, I want to use a statement with an inner join, a simplified version of which would be something like :
SELECT c.ref AS cref, sometable.*
FROM someothertable AS c
JOIN sometable ON c.customername = sometable.customer
I just did that off the top of my head, so if the sql isn't quite perfect cut me some slack - the SQL isn't the point anyhow :-) What i can't quite figure out is how to end up with a complex dataset like the above when the server processing php expects :
[code]
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable
$sWhere
$sOrder
$sLimit
";
[/code]
SELECT c.ref AS cref, sometable.*
FROM someothertable AS c
JOIN sometable ON c.customername = sometable.customer
I just did that off the top of my head, so if the sql isn't quite perfect cut me some slack - the SQL isn't the point anyhow :-) What i can't quite figure out is how to end up with a complex dataset like the above when the server processing php expects :
[code]
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable
$sWhere
$sOrder
$sLimit
";
[/code]
This discussion has been closed.
Replies
Allan
[code] /* DB table to use */
$sTable1 = "games";
$sTable2 = "gameplayers";
$sTable3 = "players";
$sTable = $sTable1 . ' LEFT JOIN ' . $sTable2 . ' ON (' . $sTable2 . '.gpgameID = ' . $sTable1 . '.gameID)';
$sTable = $sTable . ' LEFT JOIN ' . $sTable3 . ' ON (' . $sTable3 . '.playerID = ' . $sTable2 . '.gpplayerID)';
$sTable = $sTable . ' WHERE ' . $sTable1 . '.gameID = ' . $gameno . '';
[/code]
HTH
Pete.