Jump to content

drop down list - php


Ameslee

Recommended Posts

Ok, at the moment i have a-z list that people click on and then it looks up the database and displays all records that start with that letter. 

now i want to have a drop down list that is associated with another field in the same table.  I have the drop down list already on the page, im just not 2 sure about the code.  im not sure if its going to work. 

It is possible to do?  On the maintenance page, people type in the field, and sometimes its more than one thing that could be displayed in the drop down on the actual website.  Is it possible to look up this field and display the required records that are similiar to what is selected in the drop down menu?  hope u can understand what i am saying.  how would i go about it?  Should i use - $_GET['search'];

Thanks
Link to comment
Share on other sites

ok as u know i have a-z, which looks up the first name of something then displays it.

also on that page, i want a drop down menu
[code]
<select name="services">
<option value="Employment">Employment</option>
<option value="Government">Government</option>
<option value="Training">Training</option>
<option value="Rehabilitation">Rehabilitation</option>
<option value="Accomodation">Accomodation</option>
<option value="Sport and leisure">Sport and leisure</option>
<option value="Information">Information</option>
<option value="Personal support">Personal support</option>
<option value="Education">Education</option>
<option value="Transition to Work">Transition to Work</option>
<option value="Community Participation">Community Participation</option>
</select>[/code]

ok when the record is added, they can enter more than one of the services, above, into a field.

When displayed on the website - they can click on the drop down menu - then the field is looked up, and what ever they have clicked on displays

does this make more sense?
Link to comment
Share on other sites

Hello Ameslee,

I have a function that reads the prefectures of japan and then the cities that are in that prefecture ( a prefecture is like a state in USA in case you did not know)

If you change the prefecture the list of cities will change to display the cities that are in the newly chosen prefecture.

It is a mix between php and javascript.
let me know if you need help explaining anything.
I got this code from someone else (not claiming credit here) but I forgot who posted it for me.

a similar topic is discussed here
http://www.phpfreaks.com/forums/index.php/topic,115647.msg487942.html#msg487942

anatak
[code]
<?php
function location()
{
$TableName1 = 'ken';
$TableName2 = 'city';
$QuerySelectKen = "SELECT $TableName1.*
FROM $TableName1
order by KenNameLan_1 ASC;";
//echo $QuerySelectKen . '<BR>';
//open db connection READ user
read_connection();
$Result1 = mysql_query($QuerySelectKen) or die(mysql_error());
//$kens[1] = array('name'=>'ken1', 'cities'=>array(10=>'Ken1-City1', 12=>'Ken1-City2', 13=>'Ken1-City3'));
$kens = array();
while($Row1 = mysql_fetch_array($Result1))
{
    $kens[($Row1['KenId'])]['name'] = $Row1['KenNameLan_1'];
$QuerySelectCity = "SELECT $TableName2.*
FROM $TableName2
WHERE $TableName2.KenId = $Row1[KenId]
ORDER BY CityNameLan_1 ASC;";
// echo $QuerySelectCity . '<BR>';
$Result2 = mysql_query($QuerySelectCity) or die(mysql_error());
while($Row2 = mysql_fetch_array($Result2))
{
    $kens[($Row1['KenId'])]['city'][($Row2['CityId'])] = $Row2['CityNameLan_1'];
}
}
//close db connection READ USER
read_close();

//print '<pre>'.print_r($kens, TRUE).'</pre>';

print <<<LLL

<script language="Javascript" type="text/javascript">
<!--
function showKens()
{
    var kenList = document.form1.ken;
    var cityList = document.form1.city;
    var kenId = kenList.options[kenList.selectedIndex].value;
    var cityName = '';

    cityList.options.length = 0;

    i = 0;
    for (y in ken_array[kenId].city)
    {
        cityName = ken_array[kenId].city[y];
        cityList.options[i] = new Option(cityName, y);
        i++;
    }
}
var ken_array = new Array();
LLL;
foreach ($kens as $kenId=>$kenDetails)
{
    $kenName = $kenDetails['name'];
    print <<<LLL

ken_array[$kenId] = new Array();
ken_array[$kenId].name = '$kenName';
ken_array[$kenId].city = new Array();
LLL;
    foreach ($kenDetails['city'] as $cityId=>$city)
    {
        print <<<LLL

ken_array[$kenId].city[$cityId] = '$city'
LLL;
    }
}
print <<<LLL

document.write('<select name="ken" onchange="showKens()">');
for (var i in ken_array)
{
    document.write('<option value="'+i+'">'+ken_array[i].name+'</option>');
}
document.write('</select>');
document.write('<select name="city"><option value=""><option></select>');
-->
</script>
LLL;

}

[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.