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

TOPIC:

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

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 `vs4go_constructionprojects_projects.category` = `2` to the default query buildQueryWhere() section

function _buildQuery_default()
{

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

. $this->_buildQuerySelect()

. ' FROM `vs4go_constructionprojects_projects` AS a '
. ' LEFT JOIN `vs4go_constructionprojects_categories` AS _category_ ON _category_.id = a.category'

. $this->_buildQueryJoin() . ' '

. $this->_buildQueryWhere()
. ' WHERE `vs4go_constructionprojects_projects.category` = `2` '

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

Last edit: by uglykidjoe.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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

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

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

  • etc
  • etc's Avatar
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 132
  • Thank you received: 19
Try this old fashioned way:
. $this->addWhere('`category` = 2')

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

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

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 following user(s) said Thank You: admin

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

  • Page:
  • 1
Time to create page: 0.060 seconds

Dear Cook Team Firstly a massive thank you for your wonderful service!
audibleid (Forum)  

Get Started