jo.nova Posted July 21, 2008 Share Posted July 21, 2008 I'm working on modding a Joomla component. I'm not quite sure, but I'm unable to set a query: // get all the categories that are bound to a content item $sql = "SELECT #__categories.* FROM #__categories INNER JOIN #__content ON #__content.catid = #__categories.id AND #__categories.published = 1 AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' ) AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' ) GROUP BY #__categories.id ORDER BY #__content.ordering "; $database->setQuery($sql); $result = $database->loadObjectList(); for($i = 0; $i < count($result); $i++) { //get current section id $secID = $result[$i]->section; echo "Current section ID is: " . $secID . "<br />"; //query: select all category items that have the current section id $sql = "SELECT #__categories.* FROM #__categories WHERE #__categories.section = '$secID' AND #__categories.published = 1 AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' ) AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' ) GROUP BY #__categories.id ORDER BY #__categories.ordering" or die ("Could not assign query"); $database->setQuery($sql) or die ('Could not set query: '. $sql); $catResult = $database->loadObjectList() or die ('Could not load object list'); ... The script makes it to this line, then dies: $database->setQuery($sql) or die ('Could not set query: '. $sql); Can I not use $database->setQuery within the for-loop? Can't code within the loop reference variables that are in a scope above it? - Joe Link to comment https://forums.phpfreaks.com/topic/115773-unable-to-set-a-query/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.