• 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: Dynamic loading of the combox from a joomla table

Dynamic loading of the combox from a joomla table 15 years 11 months ago #7307

Hi everyone!

I have a forms which holds 2 combo-boxes.
I would like to load data from a table into the first combobox.
Also i would like to load data from a table into combobox2 but only filtered by the selection of the first combobox.

Has anyone done this before en how.

A sample or direction to a solution is appreciated.

Thx in advance,

Beertje_007
The administrator has disabled public write access.

Re:Dynamic loading of the combox from a joomla table 15 years 11 months ago #7310

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

this is how you should collect data for the first combo box.

First of all create a new Combo box. Then in the items field paste the following code:
//<code>
$db = JFactory::getDBO();
$db->setQuery("Select id, username from #__users order by username");
$users=$db->loadObjectList();
 
$str = Array('|Please select');
foreach ($users as $user)
{
	$str[]=$user->id.'|'.$user->username;
}
$str = implode("\n",$str);
return $str;
//</code>

This code selects the user id and puts it as value and the username is put as label for the combo box.

I will get back to you for the second issue, since it requires AJAX to be implemented, and I have to perform some tests.
Last Edit: 15 years 11 months ago by bogdanc.
The administrator has disabled public write access.

Re:Dynamic loading of the combox from a joomla table 15 years 11 months ago #7311

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
back for the second part of your request :)

now.. let's create a drop-down that has all your joomla articles listed, and when you change the selection of the user drop down, the articles will filter the ones created by the users in the first drop down.

create a second combo box, name it "articles" and in the Items field, type this code:
//<code>
$filter = '';
if(isset($_POST['form']['users'])) $filter = " WHERE created_by= '".intval($_POST['form']['users'][0])."'";//change the users with your combobox1 name
$db = JFactory::getDBO();
$db->setQuery("Select id, title from #__content ".$filter." order by title");
$articles=$db->loadObjectList();
 
$str = Array('|Please Select');
foreach ($articles as $article)
{
$str[]=$article->id.'|'.$article->title;
}
$str = implode("\n",$str);
return $str;
//</code>
 
The administrator has disabled public write access.

Re:Dynamic loading of the combox from a joomla table 15 years 11 months ago #7336

Thx bogdanc,

I will try your examples!

Beertje_007
The administrator has disabled public write access.

Re:Dynamic loading of the combox from a joomla table 15 years 11 months ago #7339

  • esham
  • esham's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
:( not working ..
the article id not change after select username
The administrator has disabled public write access.

Re:Dynamic loading of the combox from a joomla table 15 years 11 months ago #7341

bogdanc wrote:
back for the second part of your request :)

now.. let's create a drop-down that has all your joomla articles listed, and when you change the selection of the user drop down, the articles will filter the ones created by the users in the first drop down.

create a second combo box, name it "articles" and in the Items field, type this code:
//<code>
$filter = '';
if(isset($_POST['form']['users'])) $filter = " WHERE created_by= '".intval($_POST['form']['users'][0])."'";//change the users with your combobox1 name
$db = JFactory::getDBO();
$db->setQuery("Select id, title from #__content ".$filter." order by title");
$articles=$db->loadObjectList();
 
$str = Array('|Please Select');
foreach ($articles as $article)
{
$str[]=$article->id.'|'.$article->title;
}
$str = implode("\n",$str);
return $str;
//</code>
 

Hi Bogdanc,

Thanx for the exmaple.
The first combobox works great.
The second one does not react to the first one.

There is no postback.

Do you know what is wrong.

Thanx again,

Beertje_007
The administrator has disabled public write access.

Re:Dynamic loading of the combox from a joomla table 15 years 11 months ago #7418

  • alexp
  • alexp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 2253
  • Thank you received: 180
Hello,

You have to press the Submit button ion order to reload the drop-down with the new values. Not the best solution ....

I will try to build up a tutorial on how to achieve this with some Ajax scripts...
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.
The following user(s) said Thank You: ariannejad

Re:Dynamic loading of the combox from a joomla table 15 years 11 months ago #7428

Thx Alexp,

I realy would like an example because this is a major problem i am facing.

Thank you in advance and untill the next mail,

Beertje_007
The administrator has disabled public write access.

Re:Dynamic loading of the combox from a joomla table 15 years 9 months ago #8080

  • proexe
  • proexe's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 34
Hi

Have you been able to sort out any tutorial on this one yet as looking in to using this type of Dynamic Drop-down in one of my forms.

Can you let me know as soon as you can.

Thanks

ProExe
The administrator has disabled public write access.

Re:Dynamic loading of the combox from a joomla table 15 years 9 months ago #8160

  • ifeanyi
  • ifeanyi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Hi, i am interested in learning how to do this also...any answer?
The administrator has disabled public write access.
  • 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!