|
How to retrieve data from a database? 3 Months, 3 Weeks ago
|
Karma: 0
|
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:
| 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,
|
|
|
|
|
|
|
|
kahml
Fresh Boarder
Posts: 12
|
|
|
|
|
Re:How to retrieve data from a database? 3 Months, 3 Weeks ago
|
Karma: 0
|
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?
| Code: |
$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? 3 Months, 3 Weeks ago
|
Karma: 0
|
|
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
Fresh Boarder
Posts: 12
|
|
|
|
|
Re:How to retrieve data from a database? 3 Months, 3 Weeks ago
|
Karma: 0
|
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
| Code: |
// 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;
}
|
|
|
|
|
|
|
|
Re:How to retrieve data from a database? 3 Months, 3 Weeks ago
|
Karma: 0
|
Thank you Mark, I'll give it a try and I'll let you know if it worked for me 
|
|
|
|
|
|
|