Welcome, Guest
Username: Password: Remember me

TOPIC: [SOLVED] WHERE Query

[SOLVED] WHERE Query 14 Jun 2013 13:19 #7473

  • uglykidjoe
  • uglykidjoe's Avatar
  • Offline
  • New Member
  • Posts: 5
  • Thank you received: 1
  • Karma: 1
Can a WHERE query be added in Cook, I can see the group by that works ok on a foreign field

I can grab a parameter from the url ok because I can echo it out, how do I

select * from table name where category = $categoryid

I have tried adding WHERE `#__constructionprojects_projects.category` = `2` to the default query buildQueryWhere() section

function _buildQuery_default()
{

$query = ' SELECT a.*'
. ' , _category_.category AS `_category_category`'

. $this->_buildQuerySelect()

. ' FROM `#__constructionprojects_projects` AS a '
. ' LEFT JOIN `#__constructionprojects_categories` AS _category_ ON _category_.id = a.category'

. $this->_buildQueryJoin() . ' '

. $this->_buildQueryWhere()
. ' WHERE `#__constructionprojects_projects.category` = `2` '
Last Edit: 14 Jun 2013 13:20 by uglykidjoe.
The administrator has disabled public write access.

Re: WHERE Query 15 Jun 2013 08:13 #7474

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
This part is now totally deprecated in 2.5 (actually, even since 2.0)

The source you are showing is very old.
The model has changed and the new way is much easier.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: WHERE Query 15 Jun 2013 08:51 #7476

  • etc
  • etc's Avatar
  • Offline
  • Premium Member
  • Posts: 132
  • Thank you received: 19
  • Karma: 7
Try this old fashioned way:
. $this->addWhere('`category` = 2')
The administrator has disabled public write access.

Re: WHERE Query 17 Jun 2013 05:48 #7502

  • uglykidjoe
  • uglykidjoe's Avatar
  • Offline
  • New Member
  • Posts: 5
  • Thank you received: 1
  • Karma: 1
admin wrote:
This part is now totally deprecated in 2.5 (actually, even since 2.0)

The source you are showing is very old.
The model has changed and the new way is much easier.

Not really sure what you mean as the code has been generated by Cook (apart from my bit)

Anyway I got it to work by adding to the where function, so my where function looks like this
function _buildQueryWhere($where = array())
{
$app = JFactory::getApplication();
$db= JFactory::getDBO();
$acl = ConstructionprojectsHelper::getAcl();
$categoryid = JRequest::getVar('categoryid');



if (isset($this->_active['filter']) && $this->_active['filter'])
{
$filter_category = $this->getState('filter.category');
if ($filter_category != '') $where[] = "a.category = " . (int)$filter_category . "";


}
if (!$acl->get('core.edit.state')
&& (!isset($this->_active['publish']) || $this->_active['publish'] !== false))
$where[] = "a.published=1";

if ($categoryid != '') $where[] = "a.category= " .$categoryid."";

return parent::_buildQueryWhere($where);
}

Steve
The administrator has disabled public write access.
The following user(s) said Thank You: admin
Time to create page: 0.098 seconds

Get Started