× Support requests and general discussions

Auto populate a dropdown list

27 Jun 2012 13:26 - 28 Jun 2012 12:16 #1 by David
Auto populate a dropdown list was created by David
Hoping someone might have a possible solution to this..

I'm trying to find out how I might go about auto populating a dropdown list with the titles of articles from a certain category.

Eg I have 4-5 job listings in a 'jobs' category. The title of the each article is the name of the job. I would like these jobs titles to be the options within the dropdown list on a form.

Anyone any ideas?

Many thanks


I'm able to catch the titles of the articles that i want and put them into option tags using the following code:

function populateDropdown() {

$con = mysql_connect("localhost","user","pass");
if (!$con)
  die('Could not connect to the database: ' . mysql_error());

mysql_select_db("fusionbu", $con);

$query = ("SELECT * FROM fus_content WHERE catid='88'");

$result = mysql_query($query);

$jobsList = "";

while ($row = mysql_fetch_assoc($result)) {
$jobsList .= '<option value="' . $row['title'] . '">' . $row['title'] . '</option>';

echo $jobsList;


but i'm struggling to get that code into the fieldsbuilder.php file around line 300. i'm calling the function but getting an undefined variable error message.

anyone any ideas?

Please Log in or Create an account to join the conversation.

01 Jul 2012 13:55 - 01 Jul 2012 13:59 #2 by Graeme Moffat
Replied by Graeme Moffat on topic Auto populate a dropdown list
You're using 2.0.15, I presume. Your code looks alright* and you say you are getting the jobs list OK, but you don't show exactly what changes you have made to fieldsbuilder.php. I presume you have replaced lines 290-300 with a function call like "$result .= populateDropdown();" but the function would have to end with "return $jobsList;", not "echo..". At first I assumed the echo was there for debugging purposes.
Unless you only have the one dropdown field, you would also need to test for this using $field but I suppose you've thought of that!

* Joomla! strongly advises that any database calls are made using the JDatabase class, as described here: http://docs.joomla.org/Accessing_the_database_using_JDatabase
and to be even more pedantic, you should first get the category id (88 here) from a query of the #__categories table (or if you're adventurous, use one query with a JOIN).

Please Log in or Create an account to join the conversation.

20 May 2020 16:48 #3 by Levin den Boer
Replied by Levin den Boer on topic Auto populate a dropdown list
Hello Fox Contact,

I would like also to have a dropdown list. The first one is to choose the category, and the second one will be the list of the articles (header text) in that category.

Is that possible? I'm using joomla 3.9.18.

I'm not a technical person, i know how to add some lines in a .php file with BBEDIT. But that's it....

Hopefully someone can help me.

Please Log in or Create an account to join the conversation.