TOPIC:

different data in a select list populate from DB 1 year 11 months ago #241291

  • yvesfb's Avatar Topic Author
  • yvesfb
  • Offline
  • Expert Breezer
  • Expert Breezer
  • Posts: 180
  • Thanks: 0
Hello,
I have been able to use your example crosstec.org/en/support/online-documenta...ct-list-from-db.html
However, as I am relatively new in coding, I would need some help to modify the
$test .= "0;".$result[$i].";".$result[$i]."\n";

I will take an example if I have a table of Members, instead of the first .$result[$i]. I would like to get for instance the equivalent of the FirstName+ space + LastName information
and instead of the second .$result[$i]. I would like to get the id of the member.

How should I modify your example?
Thanks in advance
yves

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

different data in a select list populate from DB 1 year 11 months ago #241306

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10062
  • Karma: 167
  • Thanks: 809
Hi,

it depends on your database table, but let's say you have one column for firstname and another for lastname, it would look like this
$test .= "0;" . $result[$i]->firstname . " " . $result[$i]->lastname . ";" . $result[$i]->firstname . " " . $result[$i]->lastname . "\n";

Be aware that you need to address these columns in your select in order to retrieve them. Usually a wildcard automatically pulls all the columns.

Regards,
Markus

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

different data in a select list populate from DB 1 year 11 months ago #241312

  • yvesfb's Avatar Topic Author
  • yvesfb
  • Offline
  • Expert Breezer
  • Expert Breezer
  • Posts: 180
  • Thanks: 0
Hi Markus
thank you for the info, but I still some help for the columns. I tried to use the * in the select or to use the field names, but it doesn't load properly the variable.
The number of records is correct in the preview (see attached print screen, I get the 13 lines in the list, which corresponds to the number of records in my table, but the lines of the select list are empty.

the code I have (using the 3 field names I am interested in for the list):
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object
  
//Create your own query here
$db->setQuery('Select id,title,price From adint_osmembership_plans '); 
  
$result = $db->loadColumn(); //load the result from the query
$test = "";
$test = "0;Please make a selection;0\n";
for ($i = 0; $i < count($result); $i++)
{
     $test .= "0;".$result[$i]->title." ".$result[$i]->price.";".$result[$i]->id."\n";
}
 
function ff_setSelectList($name, $value)
{
     global $ff_processor;
     for ($r = 0; $r < $ff_processor->rowcount; $r++)
     {
          $row =& $ff_processor->rows[$r];
          if ($row->name==$name)
          $row->data2 = $value;
          unset($row);
     } // for
} // ff_setSelectList
 
ff_setSelectList('listepremiumfreemium', $test);

Thanks in advance
yves
Attachments:

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

different data in a select list populate from DB 1 year 11 months ago #241337

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10062
  • Karma: 167
  • Thanks: 809
Hi,

can you please change this
$result = $db->loadColumn();

to this
$result = $db->loadObjectList();

If you use loadColumn, you basically get only the the first column instead of all columns.

Regards,
Markus
The following user(s) said Thank You: yvesfb

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

different data in a select list populate from DB 1 year 11 months ago #241372

  • yvesfb's Avatar Topic Author
  • yvesfb
  • Offline
  • Expert Breezer
  • Expert Breezer
  • Posts: 180
  • Thanks: 0
Thank you Markus,
It works fine. :-)
I put the final script here below for info.
Now, I have seen that I need to make second select list based on the result of the first one to make it easier for the user.
Let's say I will use the resulting "id" of the choice made in the first list to filter the elements to insert into the second select list
I have seen that you already provided a script for 2 select boxes in crosstec.org/en/forums/3-breezingforms-f...mboboxes.html#128913
But I have difficulties to combine both scripts due to the fact:
- both elect boxes are built dynamically
- and I don't need to test the result of the first box 'choice1' of your example, but simply to select 2 fields of another table (table2) for the text + the id of that table2 for the value of the row in the select box. it will then be a second formula for the new select list like:
$test2 .= "0;" . $result[$i]->first_name . " " . $result[$i]->last_name . ";" . $result[$i]->id . "\n";

Can you please let me know how to proceed to adapt your example of crosstec.org/en/forums/3-breezingforms-f...mboboxes.html#128913 using the first select box you already helped me with (code below)?

Best regards
yves

Script resulting from the first select box (and stored in the before form):
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object
  
//Create your own query here
$db->setQuery(Select id,title,price From adint_osmembership_plans); 
  
$result = $db->loadObjectList(); //load the result from the query
$test = "";
$test = "0;Please make a selection;0\n";
for ($i = 0; $i < count($result); $i++)
{
     $test .= "0;" . $result[$i]->title . " " . $result[$i]->price . ";" . $result[$i]->id . "\n";
}
 
function ff_setSelectList($name, $value)
{
     global $ff_processor;
     for ($r = 0; $r < $ff_processor->rowcount; $r++)
     {
          $row =& $ff_processor->rows[$r];
          if ($row->name==$name)
          $row->data2 = $value;
          unset($row);
     } // for
} // ff_setSelectList
 
ff_setSelectList('listepremiumfreemium', $test);

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

different data in a select list populate from DB 1 year 11 months ago #241732

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10062
  • Karma: 167
  • Thanks: 809
Hi,

since you and another customer had basically the same requirement, I created a boilerplate form for this task that you can use:

crosstec.org/en/forums/41-breezingforms-....html?start=0#241236

Later in that thread I am extending it to a 4-dimensional selection but I guess based on your description, the 2-dimensional is fine ("make"/"model" relation).

Please check it out and let me know what you think as it might be completely different from what you got so far.

Regards,
Markus

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

Moderators: ForumSupport
Time to create page: 0.082 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!