How to retrieve data from a database? - Crosstec
Welcome, Guest
Please Login or Register.    Lost Password?

How to retrieve data from a database?
(1 viewing) (1) Guest
Go to bottomPage: 12
TOPIC: How to retrieve data from a database?
*
#14956
Re: How to retrieve data from a database? 1 Month, 2 Weeks ago Karma: 0
Hi mpadros,

I'm a little bit lost with this code you provided me with:

First I have to say that my form is in Quick Mode and I don't know if the code you provided me with is for Quick Mode or another mode.

Here's what I have:
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 `title` from `#__categories` where published=1");

$categorie="1;Veuillez choisir une;\n";

//set text,checked and selected
if (Count($rows))
{
   foreach($rows as $record)
   {
      $categorie.="0;$record->title; $record->title\n";
   }
}

}



I have kept this piece of code but I don't know what he's need for:

Code:

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



When I do that it does not populate my "select list" called categorie.
In your example you have:
ff_setSelected for radio
ff_setChecked for checked
and ff_setValue, is this for select-list?

How should I populate my select list categorie?

Thank you very much for your help.
facommunications.com
Fresh Boarder
Posts: 10
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2010/07/27 02:21 By facommunications.com.
The administrator has disabled public write access.
 
#15762
Re: How to retrieve data from a database? 3 Weeks, 2 Days ago Karma: 0
Hi facommunications,

In my example I use the rid parameter to retrieve a submitted record id. This id is then inserted in the sql query to populate a select-list.
In your case, it seems like all you want to do is populate a selectlist in your form. You could also do that like this:
- Make a selectlist
- in the element properties --> list, fill in something like this:
<?php
$userid = JFactory::getUser()->get('id',0);
$rows = ff_select("select * from `#__factureringssysteem_indo` where oauserid=$userid");
$html = '';
foreach ($rows as $row) $html .= "0;$row->omschrijving;$row->id\r\n";
return $html;
?>

As you can see, my Where clausule contains a userid, you can easily remove that for your form.

Hope this works!
Marc
mpadros
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 12
Moderators: , TheMuffinMan