Ameslee Posted December 19, 2006 Share Posted December 19, 2006 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 https://forums.phpfreaks.com/topic/31295-drop-down-list-php/ Share on other sites More sharing options...
trq Posted December 19, 2006 Share Posted December 19, 2006 Anything is possible, but the description of your problem is not very clear. Link to comment https://forums.phpfreaks.com/topic/31295-drop-down-list-php/#findComment-144827 Share on other sites More sharing options...
Ameslee Posted December 19, 2006 Author Share Posted December 19, 2006 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 displaysdoes this make more sense? Link to comment https://forums.phpfreaks.com/topic/31295-drop-down-list-php/#findComment-144833 Share on other sites More sharing options...
marcus Posted December 20, 2006 Share Posted December 20, 2006 Are you trying to say that you want to select the fields from the database and create a dropdown list out of them? Link to comment https://forums.phpfreaks.com/topic/31295-drop-down-list-php/#findComment-144847 Share on other sites More sharing options...
Ameslee Posted December 20, 2006 Author Share Posted December 20, 2006 well if thats what i have to do, yes, but because i already have one on the page, cant the code work with what i already have Link to comment https://forums.phpfreaks.com/topic/31295-drop-down-list-php/#findComment-144848 Share on other sites More sharing options...
anatak Posted December 20, 2006 Share Posted December 20, 2006 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 herehttp://www.phpfreaks.com/forums/index.php/topic,115647.msg487942.html#msg487942anatak[code]<?phpfunction location(){$TableName1 = 'ken';$TableName2 = 'city';$QuerySelectKen = "SELECT $TableName1.* FROM $TableName1 order by KenNameLan_1 ASC;";//echo $QuerySelectKen . '<BR>';//open db connection READ userread_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 USERread_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 <<<LLLken_array[$kenId] = new Array();ken_array[$kenId].name = '$kenName';ken_array[$kenId].city = new Array();LLL; foreach ($kenDetails['city'] as $cityId=>$city) { print <<<LLLken_array[$kenId].city[$cityId] = '$city'LLL; }}print <<<LLLdocument.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 https://forums.phpfreaks.com/topic/31295-drop-down-list-php/#findComment-144979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.