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.073 seconds

Although I found this tool some time ago I just started learning experimenting and building this first component on Monday and now on Thursday afternoon it's already online. Although I already had a working version done with another tool this is much easier to build and at the end you have the freedom to own your own component. Once you know how to use Cook you will boost your productivity as the learning curve is really moderate compared to many other tools.
Giori (Forum)

Get Started