if ($ds= $modx->db->query($query)) { // if the query was successful, build our table array from the rows while ($row= $modx->db->getRow($ds)) { $industries[]= array(
Hey Garry, long timeCertainly is, hope you’re keeping well.![]()
I set $ds=0; near the top to ensure it was empty then I returned $ds on the page and I got a value of Resource id #18 not a number Huh I was expecting the number of rows in the table.That’s to be expected, by returning $ds you are returning the handle on the recordset. You would need to use $modx->db->getValue() statement first and then return the results of that to the page to get the record count.
That would appear to check if $ds equals the same number as what was in $query (which is "SELECT COUNT(id) FROM modx_courses" and that returns the correct value), if its not it gets that row number from the database and puts in the array?No, the single ’=’ sign means it is assigning the results of the executed query to $ds. Because the query returns a record then the IF statement evaluates to true.
if ($ds= $modx->db->select('*','modx_courses')) {
function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "")
($ds= $modx->db->select('*','modx_courses','',$orderby))
// create the table header definition with each header providing a link to sort by that field $industryTableHeader= array( 'Code'=> $objTable->prepareOrderByLink('Code', 'Code'), 'Start'=> $objTable->prepareOrderByLink('Start', 'Start'), 'End'=> $objTable->prepareOrderByLink('End', 'End'), 'Course'=> $objTable->prepareOrderByLink('Course', 'Course'), 'Location'=> $objTable->prepareOrderByLink('Location', 'Location'), );
if ($ds= $modx->db->select('*','modx_courses','',$objTable->handleSorting(),$objTable->handlePaging())) {
MODx encountered the following error while attempting to parse the requested resource: « Execution of a query to the database failed - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id DESC LIMIT LIMIT 0, 25' at line 1 » SQL: SELECT * FROM modx_courses ORDER BY ORDER BY id DESC LIMIT LIMIT 0, 25; [Copy SQL to ClipBoard]
$sql = 'SELECT * FROM modx_courses '.$objTable->handleSorting().' '.$objTable->handlePaging(); if ($ds= $modx->db->query($sql)) {
// create the table header definition with each header providing a link to sort by that field $industryTableHeader= array( 'Code'=> $objTable->prepareOrderByLink('Code', 'Code'), 'Start'=> $objTable->prepareOrderByLink('Start', 'Start'), 'End'=> $objTable->prepareOrderByLink('End', 'End'), 'Course'=> $objTable->prepareOrderByLink('Course', 'Course'), 'Location'=> $objTable->prepareOrderByLink('Location', 'Location'),