Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Php select dropdown error

10:41 am on Jan 7, 2015 (gmt 0)

New User

5+ Year Member

joined:Feb 15, 2014
posts: 19
votes: 0

Am trying to populate select option from the database with this script but it does not display.
Am not getting any errors either

function getTierOne()
$result = mysql_query("SELECT DISTINCT tier_one FROM three_drops")
or die(mysql_error());

while($tier = mysql_fetch_array( $result ))

echo '<option value="'.$tier['tier_one'].'">'.$tier['tier_one'].'</option>';


if (isset($GET['func'])&& $_GET['func']=='drop_1'){

function drop_1($drop_var)
$result = mysql_query("SELECT DISTINCT tier_two FROM three_drops WHERE tier_one='$drop_var'")
or die(mysql_error());

echo '<select name="drop_2" id="drop_2">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';

while($drop_2 = mysql_fetch_array( $result ))
echo '<option value="'.$drop_2['tier_two'].'">'.$drop_2['tier_two'].'</option>';

echo '</select>';
echo "<script type=\"text/javascript\">
$.get(\"func.php\", {
func: \"drop_2\",
drop_var: $('#drop_2').val()
}, function(response){
setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
return false;

if (isset($GET['func']) == "drop_2" && $_GET['func']=='drop_1'){

function drop_2($drop_var)
$result = mysql_query("SELECT * FROM three_drops WHERE tier_two='$drop_var'")
or die(mysql_error());

echo '<select name="drop_3" id="drop_3">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';

while($drop_3 = mysql_fetch_array( $result ))
echo '<option value="'.$drop_3['tier_three'].'">'.$drop_3['tier_three'].'</option>';

echo '</select> ';
echo '<input type="submit" name="submit" value="Submit" />';
11:38 am on Jan 12, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 15, 2004
votes: 0

In your drop_1 and drop_2 functions you use your $_GET variables.
But in your getTierOne() function, you dont pass your $_GET data, to be used in the drop_1() function

Also, irrelevant with your question,
- in all you functions you include your db connection file. This is an overkill and can lead to unwanted results/behaviour. Include it only once.
- modify your code so as not to use mysql_ functions. They are no longer supported by php, thus its a security risk. Change to mysqli_ (note the i in the extension) or PDO functions.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members