Server side join issue
Server side join issue
I'm trying to add sJoin to my server side script, but if I add any fields with a dot "." in them (eg: 'table1.field') it throws up the error "Undefined index: table1.field"
But the dot is necessary for joining tables!
I don't think it's possible to add array keys with dots in them.
How can I solve this?
Example parts of script: $aColumns = array('table1.field', 'table2.field2');
$sTable = "table1";
$sJoin = " JOIN table2 ON table1.field= table2.field";
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable
$sJoin
$sWhere
$sOrder
$sLimit
";
But the dot is necessary for joining tables!
I don't think it's possible to add array keys with dots in them.
How can I solve this?
Example parts of script: $aColumns = array('table1.field', 'table2.field2');
$sTable = "table1";
$sJoin = " JOIN table2 ON table1.field= table2.field";
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable
$sJoin
$sWhere
$sOrder
$sLimit
";
This discussion has been closed.
Replies
Thanks
https://github.com/n1crack/IgnitedDatatables-php-library
example of joins :
https://github.com/n1crack/IgnitedDatatables-php-library/blob/master/examples/sql_joins/ajax.php
example 2 ;
[code]
$datatables
->select('first_name, last_name, email as mail, postal_code as pcode, city, country')
->from('customer')
->join('address', 'address.address_id = customer.address_id', 'left')
->join('city', 'address.city_id = city.city_id', 'left')
->join('country', 'country.country_id = city.country_id', 'left');
[/code]
simple huh? :)
The Standalone Php Fork link doesn't work by the way.
The documentation on datatables is very lack where there is zero help on joining database tables.
There are some scraps on forums about it but nothing worked and people who have had the same problem as me have had no response.
We shouldn't have to resort to using a third party library to join tables hen the server side examples do not reference this function!
Couple of questions though. I'm trying to manipulate some fields with oo functions but it's not working right:
[code]$datatables->edit("customerID", "".$customer->createCustRef($config['custPrefix'], '$1')."", "customerID");[/code]
The createCustRef function is
[code]function createCustRef($custPrefix, $customerID){
return $custPrefix.str_pad($customerID,6,"0",STR_PAD_LEFT);
}[/code]
Which adds the $config['custPrefix'] (MM) to a customer number padding it as 6 digits with zeros MM000010, MM013475 etc.
But it's always adding 4 zeros regardless of the length of the customerID number (MM000013475).
It always works fine outside of datatables.
Is there a way of manipulating the database data with php before it it used in datatables?
Also I can't see any samples of adding a column with just an image, or other data. For example the 2nd column is an image when hovering over produces a tooltip popup.
Thanks, Steve
$datatables->edit("customerID", "
Now I can't see how to add a non-database column for an image etc.
Couple more questions, if I add a custom column it always adds it to the end of the table, is there a way of adding it to be the second column for example?
Is there a way of adding a class to a TD tag (for css purposes etc)?
Lastly how I check if there are results to put in the table? If there are no results I want to put a No Results message.