• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Filter Joomla article by user id

Filter Joomla article by user id 10 years 3 months ago #29964

  • Roberts
  • Roberts's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1
I need to autopopulate a text field with article titles from jos_content. The only titles returned must be created by the current logged in user. So in effect, FROM jos_content WHERE user `id`='created_by'

I thought I could combine two popular pieces of code to achieve this -

//<code>
$items = array();
$db = JFactory::getDbo();
if ($my->get('id')) {
$db->setQuery("SELECT `title`, `id` FROM jos_content WHERE `created_by`='.$my->id.'");
$results = $db->loadObjectList();
foreach ($results as $result) {
$value = $result->id;
$label = $result->title;
$items[] = $label;
}
$items = implode("\n", $items);
return $items;
//</code>


I'm not really sure what I'm doing but it isn't working.

Any help greatly appreciated
Last Edit: 10 years 3 months ago by Roberts.
The administrator has disabled public write access.

Filter Joomla article by user id 10 years 3 months ago #29973

  • djseleco
  • djseleco's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 47
  • Thank you received: 10
If your users have a single article you can try to use this code in default value of text field:

//<code>
 
$db = JFactory::getDbo();
$user = JFactory::getUser();
 
$db->setQuery("SELECT title FROM #__jos_content WHERE created_by='". $user->get('id')."'");
$results = $db->loadObjectList();
 
foreach ($results as $res){
 return $res->title;
}
//</code>

But if your users have many articles, you need to use a dropdown field, with a query like this:
//<code>
 
$items = array();
$db = JFactory::getDbo();
$user = JFactory::getUser();
$items[] = "|- Select -[c]";
$db->setQuery("SELECT title, id FROM #__jos_content WHERE created_by='". $user->get('id')."'");
$results = $db->loadObjectList();
 
foreach ($results as $result) {
  $value = $result->id;
  $label = $result->title;
  $items[] = $value.'|'.$label;
}
 
$items = implode("\n", $items);
 
return $items;
//</code>
 
 
The administrator has disabled public write access.
The following user(s) said Thank You: Roberts

Filter Joomla article by user id 10 years 3 months ago #29974

  • Roberts
  • Roberts's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1
Thanks Dj

I thought I had tried that but I'll try again with a copy and paste.

B)
The administrator has disabled public write access.

Filter Joomla article by user id 10 years 3 months ago #29975

  • djseleco
  • djseleco's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 47
  • Thank you received: 10
I suggest you to add also:
state = 1 in WHERE syntax
otherwise appear also unpublished and trashed articles
//<code>

$items = array();
$db = JFactory::getDbo();
$user = JFactory::getUser();
$items[] = "|- Select -[c]";
$db->setQuery("SELECT title, id FROM #__jos_content WHERE state= 1 AND created_by='". $user->get('id')."'");
$results = $db->loadObjectList();

foreach ($results as $result) {
$value = $result->id;
$label = $result->title;
$items[] = $value.'|'.$label;
}

$items = implode("\n", $items);

return $items;
//</code>



//<code>

$db = JFactory::getDbo();
$user = JFactory::getUser();

$db->setQuery("SELECT title FROM #__jos_content WHERE state= 1 AND created_by='". $user->get('id')."'");
$results = $db->loadObjectList();

foreach ($results as $res){
return $res->title;
}
//</code>
Last Edit: 10 years 3 months ago by djseleco.
The administrator has disabled public write access.
The following user(s) said Thank You: Roberts

Filter Joomla article by user id 10 years 3 months ago #29976

  • Roberts
  • Roberts's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1
Tried that, no success.

I tried both single and multiple titles into dropdown, text area and text field. Nothing gets loaded in any of them.

Tried the code in the ‘items’ area in the dropdown field and the ‘default’ area in text area. No go!

It looks to me like your code should work ...very strange :S

I'm using a form to enable members to update their articles so State=0 is ok. They can publish (state=1) if they wish.
Last Edit: 10 years 3 months ago by Roberts.
The administrator has disabled public write access.

Filter Joomla article by user id 10 years 3 months ago #29977

  • djseleco
  • djseleco's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 47
  • Thank you received: 10
have you tried to replace #__ with your db table name? yourtablename_jos_content?
The administrator has disabled public write access.
The following user(s) said Thank You: Roberts

Filter Joomla article by user id 10 years 3 months ago #29978

  • Roberts
  • Roberts's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1
Yeah, the table name is jos_content

I tried

jos_content

#__content

#_content

#_jos_content

Curious!
The administrator has disabled public write access.

Filter Joomla article by user id 10 years 3 months ago #29979

  • djseleco
  • djseleco's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 47
  • Thank you received: 10
which joomla version are you using?
The administrator has disabled public write access.

Filter Joomla article by user id 10 years 3 months ago #29980

  • Roberts
  • Roberts's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1
2.5.28

I can import from Jos_rsform_submission_values without any problem so there shouldn't be a problem with jos_content ...you would think :S
The administrator has disabled public write access.

Filter Joomla article by user id 10 years 3 months ago #29981

  • djseleco
  • djseleco's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 47
  • Thank you received: 10
Strange. But you are logged in frontend of your web site?
The administrator has disabled public write access.

Filter Joomla article by user id 10 years 3 months ago #29982

  • Roberts
  • Roberts's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1
:woohoo: Its Working!

Nice one Dj
//<code>
 
$items = array();
$db = JFactory::getDbo();
$user = JFactory::getUser();
$items[] = "|- Select -[c]";
$db->setQuery("SELECT title, id FROM jos_content WHERE created_by='". $user->get('id')."'");
$results = $db->loadObjectList();
 
foreach ($results as $result) {
  $value = $result->id;
  $label = $result->title;
  $items[] = $value.'|'.$label;
}
 
$items = implode("\n", $items);
 
return $items;
//</code>

Thanks for all your help Dj
The administrator has disabled public write access.

Filter Joomla article by user id 10 years 3 months ago #29983

  • djseleco
  • djseleco's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 47
  • Thank you received: 10
Good :)
The administrator has disabled public write access.
The following user(s) said Thank You: Roberts
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!