• 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: Populate List Box from Table in Another Component

Populate List Box from Table in Another Component 16 years 8 months ago #4070

  • tobypsl
  • tobypsl's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 62
  • Thank you received: 1
Hi
I have a component that displays products (if they are set to publish). Each product is stored in a table. I would like to populate a Multi Select Drop Down List Box with a Code for each product in that table that is published.

I aimagine there is a reasonably simple MySQL SELECT statement to use.

Does anyone have some existing code (as my PHP and SQL is poor)

Ideally I'd like to concatenate two fields from the table into the list Box. The two fields are code & title with values such as:

Code.....Title..............Published
001A.....Product1A.........Yes
002B.....Product 2B.........No
003B.....Product 3B........Yes
004C.....Product 4A.........No
005C.....Product 5C........Yes

So the listbox would ideally produce a multi select list like:

ListBoxValues
001A_Product1A
003B_Product3B
005C_Product5C

selecting those products that are published and concatenating the code and title fields.

If the concatenation is a problem I would settle for listing the codes.

Any help much appreciated :cheer:
The administrator has disabled public write access.

Re:Populate List Box from Table in Another Component 16 years 8 months ago #4073

  • tobypsl
  • tobypsl's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 62
  • Thank you received: 1
I found a piece of code in the FAQ and adapted it as follows:

$database->setQuery(\"SELECT code FROM jos_prods_prod\");
$data = $database->loadObjectList();//we load the usernames

foreach($fields as $i=>$field){
if($field->name=='selection'){//cycle through the fields, and find our select box field
$string = array();
if(!empty($data)){
foreach($data as $data_row){
$string[] = $data_row->code.'|'.$data_row->code;//prepare the default syntax which will be value1|label1,value2|label2
}
}
$string = implode(',',$string);
$fields[$i]->default_value = $string;
}
}

jos_prods_prod is the table with the field code in it and selection is the multi select list box field in the form.

but the preview page is blank. My other forms seem OK so this doesn't seem to tbe the issue others have had with blank pages, I'm thinking it's something to do with the script ???

Any ideas appreciated :)
The administrator has disabled public write access.

Re:Populate List Box from Table in Another Compone 16 years 8 months ago #4076

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
First have you pro version on lite ?

Second show the message for the Select List country.
$data_row->code.'_'.$data_row->title.'|'.$data_row->code.'_'.$data_row->title<br><br>Post edited by: dragonjc, at: 2008/08/10 08:31
Component RS SHow Form in build
The administrator has disabled public write access.

Re:Populate List Box from Table in Another Compone 16 years 8 months ago #4077

  • tobypsl
  • tobypsl's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 62
  • Thank you received: 1
Hi Dragonjc

I have the pro version ...
The administrator has disabled public write access.

Re:Populate List Box from Table in Another Compone 16 years 8 months ago #4084

  • tobypsl
  • tobypsl's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 62
  • Thank you received: 1
so having waded through a ton of posts on this forum it seems the simple answer is no that script DEFINTELY WILL NOT WORK with the pro version.

so my question is, given that the FAQ for the RS Forms product has a script tutorial to achieve populating a drop down list (presumably because this is a popular requirement) where is the similar tutorial for the Pro version ?

In fact where is the FAQ for the Pro version ?
The administrator has disabled public write access.

Re:Populate List Box from Table in Another Compone 16 years 8 months ago #4088

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
the way is easy, wait for monday and i will paste my code who works, very very good.

www.rsjoomla.com/index.php/RSform-Script...elect-list.html#3820<br><br>Post edited by: dragonjc, at: 2008/08/10 21:15
Component RS SHow Form in build
The administrator has disabled public write access.

Re:Populate List Box from Table in Another Compone 16 years 8 months ago #4089

  • tobypsl
  • tobypsl's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 62
  • Thank you received: 1
is monday a better day for posting code than sunday ? I guess sunday is the day of rest, fair enough, I look forward to the good code on monday, thanks dragonjc :)
The administrator has disabled public write access.

Re:Populate List Box from Table in Another Compone 16 years 8 months ago #4090

  • tobypsl
  • tobypsl's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 62
  • Thank you received: 1
hi dragonjc
there are 2 pieces of code in the post you linked:
$database-&gt;setQuery(\&quot;SELECT countries_name FROM #__form_countries\&quot;«»);
$data = $database-&gt;loadObjectList();
 
foreach($fields as $i=&gt;$field){
    if($field-&gt;name=='countryselect'){
        $string = array();
        if(!empty($data)){
            foreach($data as $data_row){
                $string[] = $data_row-&gt;countries_name.'|'.$data_row-&gt;countries_name ;
            }
        }
        $string = implode(',',$string);
        $fields[$i]-&gt;default_value = $string;
    }
}

and haboyes comments that this does not work in the RSFormsPro version and he seems to be correct, I have tried numerous different versions of this, as there are examples thorughout the forum, and all result in a blank screen when previewing the form.

He posts the following code as a fix:
//&lt;code&gt;
$q=\&quot;SELECT `iso`,`countries_name` FROM `jos_form_countries`\&quot;;
$rez=mysql_query($q) or die(mysql_error());
$out='';
while($r=mysql_fetch_array($rez)) $out.=$r[0].'|'.$r[1].\&quot;\n \&quot;;
return $out;
//&lt;/code&gt;

The query seems to be accepted as my form loads but the listbox has not been populated and looking at the code (even with just basic knowledge) I didn't think it would. Presumably there is more to get it to populate the listbox. How, or where, do I insert the above code from haboyes to load the listbox :huh:
The administrator has disabled public write access.

Re:Populate List Box from Table in Another Compone 16 years 8 months ago #4091

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
The last code is the good one, you can insert them (with tag //<code></code) into your items values from the select list of your choise.
Component RS SHow Form in build
The administrator has disabled public write access.

Re:Populate List Box from Table in Another Compone 16 years 8 months ago #4103

  • tobypsl
  • tobypsl's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 62
  • Thank you received: 1
HI dragonjc

I have inserted the second piece of code in the items for the list box, ammending the field names to match my component table. The form loads but the list box is empty.

Any ideas ?
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!