Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Adding a WHERE... OR... to the database class 28 Mar 2012 17:13 #1769

I am OK with PHP and MySQL but not got the MVC thing right yet. A few questions about editing the database class please.

1

My challenge is to add a '...WHERE ... OR ....' clause to a query (I have followed instructions on adding a WHERE by itself)

What I have at the moment is
function _buildQueryWhere($where = array())
	{
		$app = JFactory::getApplication();
		$db= JFactory::getDBO();
		$option	= JRequest::getCmd('option');
		$view	= JRequest::getCmd('view');
		$layout	= JRequest::getCmd('layout', 'default');

		$baseUserState = $option . '_' . $view . '.' . $layout . '.';
		

		if (!isset($this->_active['publish']) || $this->_active['publish'] !== false)	$where[] = "a.publish=1";



		return parent::_buildQueryWhere($where);
	}





This checks whether the category is published and then includes it. I'd like to override this with an OR. There is a field in the categories table called 'added_by' which includes the id of the user who added it. I'm used to normal SQL, but not Joomla database way of doing things. What I'd like is something that will have this effect:

...WHERE ('publish' = 1 OR 'added_by' = $userid)... or ...WHERE ('publish' = 1 || 'added_by' = $userid)...

So that it is included even if it's not published only if it is that user's own category

How can I do this? I'm fine getting the user id into a variable, but how to I add a WHERE..OR.. clause to the model above?

Many thanks in advance for you guidance

Please Log in or Create an account to join the conversation.

Last edit: by andypooz.
  • Page:
  • 1
Time to create page: 0.046 seconds

I'm playing around with the new mvc and the FORK feature is FANTASTIC!!! it's saving me a lot of time! you are doing a very good job!!

Tomaselli (Forum)  

Get Started