Hello,
Sorry for this stupid question, I'm not a PHP expert.
I would like to populate a drop down list with data located within a joomla table (from "Seminar" component) to choose one event.
I created my form,
Is there somewhere a tutorial (I found many interesting contributions bur not what I'm looking for) explaining how populate this drop down box and how to select a value (or multiple values).
Thanks in advance
Hi,
I will edit one of the code blocks:
<DIV class=form_item >
<DIV class="form_element cf_dropdown" ><LABEL class=cf_label >sélectionner un événement</LABEL>
<?php
$db =& JFactory::getDBO();
$query = "
SELECT title
FROM `jos_seminar`;
$db->setQuery($query);
$rows = $db->loadResultList();
?>
<SELECT class="cf_inputbox validate-selection" id=select_3 size=1 name=select_3 >
<?php
foreach ($rows as $row) {
echo "<option value='$row'>$row</option>";
}
?>
</select>
</DIV>
<DIV class=clear > </DIV></DIV>
Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Hi cobayecrau,
What code are you using? I'm sure this - JDatabaseMySQL::loadResultList() -wasn't in anything Max posted. It's not meaningful Joomla code.
Bob
Well, those are typos!! it was too late when I did this and I didn't recheck the code!!
🙂 you need to close the query string :
$query = "SELECT title FROM `jos_seminar`;"
Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Hi cobayecrau,
`jos_seminar` is correct - MySQL names should be enclosed in back-ticks and values in 'value' single quotes
Bob
PS Though to be good Joomla that should be `#__seminar` to let Joomla set the table prefix :-)
Hello.
I've follow this tread because I've the same problem, and searching, I found thatloadResultList seems doesn't exist...
Maybe change this the code will be correct....???
Sorry for my bad english...
Hi Rias,
Yes, you are correct; that should be loadResultArray I think.
Bob
Thanks Bob,
Then guess it should be rows = $db->loadResultArray; ??
Thanks so much Bob!!!
Now it's working ok... my next step it's to fill a textfield depending a select value for my drop down list hehehe
Thank you again!
Ok, I've populate my dropdown with this code, but now, i want to add data to a text field when I select a element ffor my dropdown list....
Example, my table "friends" have te data "name", "age", "address", so on... I populate my dropdown list with "name", when I select Karla, text field "addres", "age" and "x" filled up with data form Karla....
I've seen so many examples in php and js but I'm really lost... have somebody any idea about this??
Thanks!
Hi Rias,
you will need to create a dynamic JS function and use the onChange event of the select element to load the data in the 2 fields, this is alittle advanced!
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Good idea !
Nevertheless I think $row and $current are already defined as keywords for PhP (not sure ?)
No, I dont think so!🙂
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Hi smappler,
Did you use the code I posted at the other topic ? you can edit it very easily to do this!
Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
I want to do the same thing. I understand how to create the php code. The problem is that I can't find the file to put the code into. My form I have created is called eventreg. I've looked under the componants/com_chronocontact and cannot find a file name of eventreg. Can someone tell me where the file resides so that I can make the changes?
Thanks. Love the software! I paid the $25 just because it is well worth it!!
Anne
Hi Anne,
To add code to your form - or to edit the Form HTML, open the form in the ChronoForms Form Manager and click the Form Code tab. You can open or close individual widows by clicking the +- signs.
Bob
try loadRowList instead ?
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Same result. I am doing something wrong. It works perfectly with loadResultArray...
Guess I need to stick with that. Thanks for your help.
oh, my mistake, yes, your code supports only 1 array, so you should use the loadResultArray!
Regards
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
How ould I do if I want the resulting values in the form to be unique?
I tried with "DISTINCT" in the sql-query but it seems to go through all columns.
Edit:
Found it out myself. "GROUP BY column_name" worked the charn in the sql-query.
Hi crisscross.
I don't recognise $rows = $db->loadResultArray(5); what's the '5'?
You are setting the array index as the value of the option so it will be a number.
Bob
Hi diva,
The code basically looks OK. It's better not to use $rows or $row as Joomla also uses these values and that may be why your page is getting messed up. Try $devices and $device instead.
The next step is to set Error Reporting to Maximum in the Site Global Configuration and see if you get a meaningul error message instead of a blank page.
Bob
Hi diva,
Hmmmm ... I don't see anything else in there. Please make sure that the update is saved then re-load the form page.
Bob
Hi, I reset safari, clear cache, restart mamp, i still got the error.
Hi Diva,
Please re-post the current Form HTML and the error message you are getting.
Bob
Hi Yahhr,
The code is here several times but that's a perfectly good version of it.
Bob
Ok I wondered, because all the ones I see (and have tried) load the same variable in value and visible text in the pull-down menu. This one loads the variable ([user_id] from jos_user) in the value, and the name of the person ([name] from jos_user) in the visible pull-down. Maybe I am blind (age does that), but I certainly do not see this form of this code snippet anywhere in here.
My apologies!
Hi Yahhr,
Apologies - I'm not sure that combo is here. I was thinking more generally about populating a drop-down from the database.
Bob.