Welcome, Guest

How to retrieve data from a database?
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: How to retrieve data from a database?

How to retrieve data from a database? 2 years ago #13579

Hi,

I'd like to know if it is possible to retrieve data from a database with Breezingform.

I know that with this piece of code:
$db = JFactory::getDBO();

$query = "SELECT content_id"
. " FROM #__content_frontpage"
. " WHERE content_id = $item_id"
. " LIMIT 1"
;

I can retrieve data from a db in Joomla but is it possible to do this with Breezing form?

and would it be possible to pre-populate a select-list with this data?

Thank you,

Re: How to retrieve data from a database? 2 years ago #13582

Here's the KB article that describes pretty much what you want to do: www.crosstec.de/support/index.php?pid=kn...wentclient&id=52

Hope that helps!

Larry
  • kahml
  • OFFLINE
  • Fresh Boarder
  • Posts: 12
  • Karma: 0

Re:How to retrieve data from a database? 2 years ago #13594

Hi Larry,

I'm not a big programmer.
When it says:

You will need to write a 'Before Form Piece' - a small PHP script that gets executed before the form is loaded. Within it, you can specify a SQL statement, query the database and put the results into your form.

Does it means that I have to do the following to get the data from the table?
$db = JFactory::getDBO();

$query = "SELECT content_id"
. " FROM #__content_frontpage"
. " WHERE content_id = $item_id"
. " LIMIT 1"
;


The values of a select-list have the form 0;foo;bar so all you need to do is to dynamically build a string with the desired values and then provide it to the function mentioned below.

Here I don't know exactly what to do

Did you already done that in the past? Do you have an example that I could use?

Thank you very much for you time and help, is very appreciated.

Re:How to retrieve data from a database? 2 years ago #13595

In BreezingForms, to fill a list programatically, you need to supply 3 values. That's a translation of what "have the form 0;foo;bar" means.

So, if your database has, for example, a list of items with their itemID, you'd have a list like:

0;Garden shears;gs101
0;Tough gloves;$tg103
0;Hand claw;hc102

Your code example - especially with the LIMIT 1 parameter - will only provide one value, so I'm not sure why you even want to use a list. Just the same, it will not work to fill the select list in BF.

The sample code in the KB article shows what a loop looks like, and formats a variable to contain each of the 3 parts used to create the drop-down/select list.

How to implement this code is explained at the bottom. You open your form, click on the Advanced tab, click on the link for More options, click on the tab for Form Pieces, then in the "Before Form" section, select the "Custom" option. You enter your code in the box that opens up. Click Save repeatedly to save your work.

Sorry, but I don't have an example to show you.

Hope that helps!

Larry
  • kahml
  • OFFLINE
  • Fresh Boarder
  • Posts: 12
  • Karma: 0

Re:How to retrieve data from a database? 2 years ago #13598

Hi facommunications.com,

check my code snippet below. I use this to populate fields after submitting the form (populate on reload). That's where the "$rid = ff_getParam('ff_param_rid');" is for. See whether you can work this out for your form.

Greets,
Marc


// load the standard form creation utilities
$this->execPieceByName('ff_InitLib');

//set globals
global $record;

//set value of id
$rid = ff_getParam('ff_param_rid');

//load existing data
global $record;

//check id has value
if($rid){

//query db
$rows = ff_select("select * from `#__ondersteuningsaanvragen` where id=$rid");

//set text,checked and selected
if (count($rows)) {
   $record = $rows[0];

		




   //set edit radio checked
   ff_setSelected('budgeted', $record->budget);
   //set edit checkbox checked
   ff_setChecked('medewerkered',$record->medewerker);
   ff_setChecked('systematischereviewsed',$record->systematischereviews);
   ff_setChecked('kwantitatiefonderzoeked',$record->kwantitatiefonderzoek);
   ff_setChecked('indicatorenontwikkelinged',$record->indicatorenontwikkeling);   
   ff_setChecked('projectvoorsteled',$record->projectvoorstel);
   ff_setChecked('andersed',$record->anders);
   ff_setChecked('competentiesed',$record->competenties);
   ff_setValue('editid',$record->id);
   ff_setValue('datumed',$record->datum);
   ff_setValue('aanvragered',$record->aanvrager);
   ff_setValue('omschrijvinged',$record->omschrijving);
   ff_setValue('werkzaamhedened',$record->werkzaamheden);
   ff_setValue('startdatumed',$record->startdatum);
   ff_setValue('einddatumed',$record->einddatum);
   ff_setValue('tijdsinvesteringed',$record->tijdsinvestering);
   ff_setValue('begrotinged',$record->begroting);
   ff_setValue('projectnummered',$record->projectnummer);
   ff_setValue('opmerkingened',$record->opmerkingen);
} else {
   $record = NULL;
}

} else {
   $record = NULL;
}
  • dpasveer
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0

Re:How to retrieve data from a database? 2 years ago #13606

Thank you Mark, I'll give it a try and I'll let you know if it worked for me
  • Page:
  • 1
  • 2
Moderators: TheMuffinMan, ForumSupport
Time to create page: 0.41 seconds

Facebook Discount - 40% Off!

Fans of our Facebook page here are entitled to get a 1-year-subscription for the price of a 6-months!

Steps to take:

  • Become a fan on Facebook (Like) here
  • Purchase a 6-months-subscription from here
  • Write a quick email to This email address is being protected from spambots. You need JavaScript enabled to view it. with your username and prove of your like and we'll upgrade to the 1-year-subscription

Joomla!® Forms Discount - 40% Off!

Already purchased a forms extension from a different vendor but your requirements changed and now you need a forms extension that is capable of more than just the standards? We help you to keep the costs for a change under control: Get a 40% discount on our professional membership plan! -- meaning timely unlimited access to all current and future commercial extensions, breezingforms themes & apps and Joomla!® templates at crosstec.de, including 1 year of support -- without any website limitations -- Just prove that you previously purchased another forms extension for Joomla!® from a different vendor and you are qualified.

Steps to take:

  • Purchase a 1-year-subscription from here
  • Write a quick email to This email address is being protected from spambots. You need JavaScript enabled to view it. with your username and prove of the purchase for the other form vendor and we'll upgrade to the professional-subscription

About

Crosstec GmbH & Co. KG

Bergisch-Gladbacher-Str. 829

51069 Cologne, Germany

Imprint