Forums

Querey in "WHERE SQL" [SOLVED]

erict 23 Jun, 2009
For me to be able to limit the results based on a drop down search I need to perform a query in the WHERE SQL in ChronoConnect. Is there a way to do this?

I need to do this to generate a "WHERE myID IN(num,num,num)" since I am testing against a one to many relationship form a separate table.

Right now the error i get is: Fatal error: "Call to a member function setQuery() on a non-object in /*snip*/components/com_chronoconnectivity/libraries/connection.php(155) : eval()'d code on line 24" If that helpful to any one.

Thanks in advance!

- Eric
erict 23 Jun, 2009
I just figured out the solution to this and though I would share.

The current code DOES NOT work in the Query Related Settings: WHERE SQL
if(JRequest::getVar('search_id'))
{
	$idArray = array();

	$myID = JRequest::getVar('search_id');

	$database->setQuery( "SELECT * FROM jos_chronoforms_TABLE_NAME WHERE id = $myID ORDER BY id");
	$idList = $database->loadObjectList();
	
	foreach($idList as $currentID)
	{ 
		$idArray[] = $currentID->id;
	}

	echo "WHERE id IN(" . implode(",", $cArray). ")";
}


BUT, by adding "$database =& JFactory::getDBO();" we can avoid the error I mentioned in the OP.
if(JRequest::getVar('search_id'))
{
	$database =& JFactory::getDBO(); // ADDED HERE
	$idArray = array();

	$myID = JRequest::getVar('search_id');

	$database->setQuery( "SELECT * FROM jos_chronoforms_TABLE_NAME WHERE id = $myID ORDER BY id");
	$idList = $database->loadObjectList();
	
	foreach($idList as $currentID)
	{ 
		$idArray[] = $currentID->id;
	}

	echo "WHERE id IN(" . implode(",", $cArray). ")";
}
This topic is locked and no more replies can be posted.