Forums

select box from database entries

gatekeepa 13 Sep, 2011
hello everybody,

im trying to fill a select box in my form from data from a database table.
the field name is "name_de-DE".

i added "db record loader" before "show html" and added the field name, table name, and a "model id" (ProductName) for the field.
now i'm just trying to echo all "field names" with a simple, custom code script, but it won't work.

<?php
echo "test";
foreach($form->data['ProductName'] as $productname):
echo $productname['name_de-DE'];
echo $form->data['ProductName'];

endforeach;
?>


can anybody put me in the right direction and tell me how to work my way into getting the data in a select box?

best regards, gatekeepa
Max_admin 13 Sep, 2011
Hi,

if your field name matches the table column name then it should auto fill, you should first check if your table returns any data with your current settings, add a "debugger" action after the "db record loader" and see what it shows, if it doesn't show the data from your table then you have something wrong

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gatekeepa 14 Sep, 2011
thank you for you quick reply. i added a debugger to my form, this is what i get:

Debug Data
db_record_loader
SELECT * FROM `xx6fh_jshopping_products` AS `productname` WHERE `name_de-DE` = ''


still im totally blanking here. am i right on my idea to fetch all data under "name_de-DE" and put them in a productname['...'] array to show them in a input box within my form?

still trying to echo the fetched data, but getting no output :/

regards, gatekeepa
GreyHead 16 Sep, 2011
Hi gatekeepa,

The WHERE clause WHERE `name_de-DE` = '' will return all the entries where name_de-DE is empty. Is this what you want?

Bob

PS There may also be problems because of the dash in the column name - ChronoForms and MySQL sometimes have problems with them.
gatekeepa 18 Sep, 2011
hi greyhead, thank you for your post

i want to load all entries unter the fieldname `name_de-DE` from the table `xx6fh_jshopping_products` into an array called productname[].
the correct mysql select would be:
SELECT `name_de-DE` FROM `xx6fh_jshopping_products` AS `productname` 


right?
then i want to show the results as a checkbox list in my chronoform.

i cant figure out how to setup chronoforms, to function as i wish.

regards, gatekeepa
GreyHead 18 Sep, 2011
Hi gatekeepa,

Use a Custom Code action and add a Code snippet like this one:
<?php
$db =& JFactory::getDBO();
$query = "
  SELECT DISTINCT `name_de-DE`
  FROM `#__jshopping_products` ;
";
$db->setQuery($query);
$productnames = $db->loadObjectList();
?>
<select class="" id="productname" size="1" title="" name="productname">
  <option value="">==??==</option>
<?php
foreach($productnames as $p) {
  echo "<option value='".$p->name_de-DE."'>".$p->name_de-DE."</option>";
}
?>
</select>

Bob

Please also see the PS in my previous post.
marcelov 04 Mar, 2012
Hello everybody,

I have a form with several text boxes and a selection box that should insert information in a table
Im trying to fill a select box with a list of codes from a database table.
I use a multirecord loader and create a array call 'ArraySede' with the information of the field Sede_Id of the database table Sede.
I use this setence to fill my select box in a customc code

<select class="" id="Sedes" size="1" title="Sedes" name="Sedes">
<option value="">Sedes....</option>
<?php
foreach($form->data['ArraySede'] as $p) {
echo "<option value='" .$p['Sede_Id']. "'>"
.$p['Sede_Id']. "</option>";
}
?>
</select>

But the problem is that this object is outside the form generated through the wizard
and I need this selection box is part of a form that will load a new table through an Submit even.

Any idea ?? How I can resulver this problem?
Thank in advance
Marcelo 🙄
GreyHead 04 Mar, 2012
Hi Marcelo.

I think that this will work if you put your code into a Custom Element element on the Preview tab instead of the Custom Code action on the Events tab.

Bob
This topic is locked and no more replies can be posted.