Welcome, Guest
Username: Password: Remember me

TOPIC: Get data out of another table using the model?

Get data out of another table using the model? 28 Sep 2012 09:12 #4119

  • cefnllys
  • cefnllys's Avatar
  • Offline
  • Premium Member
  • Posts: 102
  • Thank you received: 5
  • Karma: 1
Hi, i was wondering if you could give me some help with regards to getting data from two tables in the model view e.g. i have a list view wich has a user_id for each entry. I need to use that user_id to display the username by pulling the username out of the #__users table within joomla itself. how would i go about doing this, I have attached some images to help explain.



please help im guessing its not that hard i just dont understand how the querys are constructed in the model.
The administrator has disabled public write access.

Re: Get data out of another table using the model? 28 Sep 2012 09:40 #4122

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
If you drag what is essentially the same field onto the grid, but instead of selecting the parent node (users), expand it and select the username, name, email or any other field available form users' table.

hope it helps,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Re: Get data out of another table using the model? 28 Sep 2012 11:03 #4125

  • cefnllys
  • cefnllys's Avatar
  • Offline
  • Premium Member
  • Posts: 102
  • Thank you received: 5
  • Karma: 1
Hi thanks for the reply although i still dont quite understand i think my main problem lies with acctually querying two databases in one model view,
I have a few questions regarding this auto generated code that if answered may help me on my way:

a) In the text highlighted in red (below) does the 'AS a' assign that table to the alias of 'a'?
b) Where/How do i add my WHERE query?
c) How do I reference another table and query it within this code dependant on a competitonID from the table being refrenced?

I should add that this is from an item view not a list view anymore.
function _buildQuery()
{

if (isset($this->_active))
switch($this->_active)
{
case 'entriesitem': return $this->_buildQuery_entriesitem(); break;

}



$query = 'SELECT a.*'
. $this->_buildQuerySelect()

. ' FROM `#__spotit_entries` AS a'
. $this->_buildQueryJoin()

. $this->_buildQueryWhere()

. '';

return $query;
}

function _buildQuery_entriesitem()
{

$query = 'SELECT a.*'
. $this->_buildQuerySelect()

. ' FROM `#__spotit_entries` AS a'
. $this->_buildQueryJoin()

. $this->_buildQueryWhere()

. '';

return $query;
}



function _buildQueryWhere($where = array())
{
$app = JFactory::getApplication();
$acl = SpotitHelper::getAcl();

$where[] = 'a.id = '.(int) $this->_id;



return parent::_buildQueryWhere($where);
}

Thanks once again any help is appreciated.
The administrator has disabled public write access.

Re: Get data out of another table using the model? 28 Sep 2012 11:09 #4126

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Turn to V2.0 to play with where if you can. It is MUCH easier.

If not :

In the caller (VIEW, almost of the cases)
$model->addWhere('a.myField = xxx');

xxx must be quoted or escaping, you know that.

You have your answer for 'a'.
'a' is always regresenting the main entry point table of your context model.

Hope it helps.

Last message until monday, I think.
Have a nice Week end.
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.067 seconds

Get Started