Jump to content

unable to set a query


jo.nova

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.