PHP - Selection code

Asked By Bigboy on 29-Jun-12 05:20 AM
Earn up to 10 extra points for answering this tough question.
Hie, can I please have PHP code for selecting an item in a combo box and the next combobox would dispaly respective items. For example: in one combo box a user can select 'mining' and in the next combobox, only 'underground mining' and 'open cast mining' would be displayed.

thank you
Jitendra Faye replied to Bigboy on 29-Jun-12 08:28 AM
Reference from-

http://stackoverflow.com/questions/6857287/how-to-make-a-cascading-drop-down-list-in-php-using-jquery

solution-


Here is sample code to implement cascading dropDownList in PHP.

$("#country").change(function(){
    $
('#city').find('option').remove().end(); //clear the city ddl
   
var country = $(this).find("option:selected").text();
    alert
(country);
   
//do the ajax call
    $
.ajax({
        url
:'getCity.php'
        type
:'GET',
        data
:{city:country},
        dataType
:'json',
        cache
:false,
        success
:function(data){

        data
=JSON.parse(data); //no need if dataType is set to json
         
var ddl = document.getElementById('city');                      

         
for(var c=0;c<obj.length;c++)
             
{              
               
var option = document.createElement('option');
               option
.value = obj[c];
               option
.text  = obj[c];                          
               ddl
.appendChild(option);
             
}


   
},
        error
:function(jxhr){
        alert
(jxhr.responseText);

   
}
   
});

});

in your getCity.php

$country = $_GET['city'];

//do the db query here

$query  
= "your query";
$result
= mysql_query($query);
$temp
= array();
while ($row = mysql_fetch_assoc($result)) {

 
if(empty($temp))
 
{
   $temp
=array($row['city']);
 
}
 
else
 
{  
   array_push
($temp,$row['city']);
 
}

}
echo
(json_encode($temp));
Super Man replied to Bigboy on 29-Jun-12 02:33 PM

Following example is using two combobox. which show how to get data from table and echo (print) it. you can make use of it. and first clear the combo box and add new data.


<?php
//**************************************
// Page load dropdown results //
//**************************************
function getTierOne()
{
$result = mysql_query("SELECT DISTINCT country FROM $tablename")
or die(mysql_error());

while($tier = mysql_fetch_array( $result ))

{
echo ''.$tier['country'].'';
}

}

//**************************************
// First selection results //
//**************************************
if($_GET['func'] == "country" && isset($_GET['func'])) {
material($_GET['drop_var']);
}

function material($drop_var)
{
include_once('config.php');
$result = mysql_query("SELECT * FROM $tablename WHERE country='$drop_var'")
or die(mysql_error());

echo '';

while($drop_2 = mysql_fetch_array( $result ))
{
echo ''.$drop_2['cities'].'';
}

echo ' ';
// echo '';
}
?>

bharti odedra replied to Bigboy on 02-Jul-12 07:49 AM
try this
1)

if you're using them within a form im sure that you would still use the POST method and then pick it up from the next page as $_POST['menuID'] like a normal form... or if it's not a form you could use $_GET though $_POST is better as the info won't show in the address bar 2)

On the select element you have to use the onChange event and trigger the function that will fill the other select 3)

select box 1

<select  name="list1"  id="list1">
 
<option value="">select</option>
<option
value="1">option1</option>
 
<option value="2">option2</option>
<option
value="3">option3</option>
</select>


your dynamic combo

<div  id="ajax_input">
<select
name="list2" id="list2">
<option
value="">select</option>
</select>

</div>


script

$('#list1').change(function(){

var
value  = $(this).val();

$
(
"#ajax_input").load("serverpage.php?value="+value);

});


you can generate your dynamic select box on

serverpage.php

this will work in

onchange

event not in submit

Bigboy replied to bharti odedra on 03-Jul-12 04:11 AM
My problem is I am new to this, can you add all the code for me for the server.php file. Thanks
help
Hi all, How do I link : http: / / www.codeproject.com / KB / architecture / MultiColumnFlatCombo.aspx http: / / www.codeguru.com / cpp / controls / combobox / multicolumncombos / article.php / c1825 / http: / / www.codeproject.com / KB / combobox / multicolumncombo.aspx http: / / www.codeproject.com / KB / combobox / Multicolumn_ComboBox.aspx http: / / www2.syncfusion.com / library / classref / Syncfusion.Windows.Forms.Tools.MultiColumnComboBox.html http www.brothersoft.com / downloads / multicolumn-combobox.html http: / / www.edneeis.com / control.aspx?ID = 7 Best Luck!!!!!!!!!!!!!!!! Sujit. Use this: Create to fill can be used. The MultiColumnCombobox class is inherited from the System.Windows.Forms.Combobox class. protected override void OnDropDown(System.EventArgs e){ Form parent = this .FindForm(); if ( this .dataTable is shown upper but the popup grid is shown below. It's not looks like combobox. Thanks R. Eswaran Hi all, How do I create MultiColumnComboBox in .Net? please tell me
On my Userform, there is one ComboBox with 5 TextBoxes. Depending what is selected on the dropdown list of the ComboBox will depend what is displayed in the TextBoxes. The problem I have is that when Miscellaneous Discussions UserForm1.TextBox1.Value (1) UserForm1.TextBox2.Value (1) Office (1) ComboBox1.Value (1) ComboBox (1) Stef (1) Textbox (1) Ezt (1) hoyos;581328 Wrote: What's your current code p45cal *p45cal* - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - p45cal's Profile: 558 View this thread: http: / / www.thecodecage.com / forumz / showthread.php?t = 160804 [url = "http: / / www.thecodecage.com"]Microsoft Office Help[ / url] Maybe you should create not work. I still need to select a textbox, after selecting a item from the combobox, for the figures to update. p45cal;581451 Wrote: Really, it would be useful. . - - p45cal *p45cal* - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - p45cal's Profile: 558 View this thread: http: / / www.thecodecage.com / forumz / showthread.php?t = 160804 [url = "http: / / www.thecodecage.com"]Microsoft Office Help[ / url] p45cal is right: then post your code! - - Regards! Stefi ???hoyos??? ezt ??rta: keywords: ComboBox, problem description: On my Userform, there is one ComboBox with 5 TextBoxes. Depending what is
I need to edit many .php file using EW2 All Unicode characters (in Vietnamese language) got distorted, and I can't Your help is greatly appreciated. Bill Expression Web Designer Discussions Expression Web (1) UTF (1) PHP (1) ANSI (1) UTP (1) ValidatorDear (1) WEB (1) DocumentHTML (1) It seems that your Default page encoding". Select Be sure to create a "meta" encoding before you save a .php file in xWeb because .php files without a "meta" encoding declaration are saved with ANSI encoding. I consider this a to "File > Properties. . . > Language" and choose "Unicode (UTF-8)" from the "Save the document as" combobox and click "OK". Furthermore, the "Default page encoding" setting is not available for are not or "meta" elements, include a comment as follows: This code is a comment for the PHP interpreter, but is recognized by xWeb. - - Dear Christoph; This is a bit more work but your files really lack this "meta" declaration? I was not sure about that because most PHP programmers complain that xWeb has a strong preference for UTF-8 while their .php files
a VC++ 6.0 code into VS 2005. it is the code of Typing Aid ComboBox comes from http: / / www.codeguru.com / cpp / controls / combobox / article.php / c4951 / . Looks like std::vector does not support erase items like array anymore. m_vSections.erase am doing wrong? Also, if you guys have a better reference for a Typing Aid comboBox (show muitiple Col in the drop down, when user type, looking for the first match width; m_vSections[i].y - = width; } } } VC MFC Discussions Vector.Erase (1) DeleteChars (1) SectionSet (1) ComboBox (1) VSections.begin (1) VSections.erase (1) VecItr (1) Iterator (1) On Wed, 20 Feb a VC++ 6.0 code into VS 2005. it is the code of Typing Aid ComboBox comes from www.codeguru.com / cpp / controls / combobox / ar
Que tal amigos : Recurro a vuestras ideas. . . Resulta que tengo varios Combobox que los vengo utilizando de una manera digamos optima y funcional para el ingreso y consulta de datos. El tema esta que al tener un Combobox Expandido no me permite ingresar un nuevo item dentro del mismo, pero si no esta expandido ahi si es posible ingresar un nuevo item e insertarlo dentro del Combobox ya sea a travez de un formulario de ingreso. . . Como podria hacer cuando el usuario ingresa recien a un Combobox y este aparezca ya expandido y se detecte que se esta digitando el primer caracter no contenido en la tabla como un nuevo item el comboBox este ya no expandido. . . Estuve probando el siguiente codigo pero no funciona como lo deseaba A la espera de sus sugerencias me despido de ustedes. . . atte., Gabriel FoxPro - Spanish Discussions ComboBox (1) Recientemente (1) Expandido (1) Portafox (1) Problema (1) Zaragoza (1) Resulta (1) Gabriel (1) Recientemente publique en Portafox este articulo - -- Combobox con busqueda incremental, abierto y desplegado - -- http: / / www.portalfox.com / index.php?name = News&file
Lien_formulaire / requête_quand_champ_vide DataBase Bonjour J'ai un formulaire avec 6 combobox. Et une requ = EAte qui d = E9pend des valeurs de mes combobox. Si je remplis mes 6 combobox, ma requ = EAte donne un r = E9sultat. Si une de mes combobox est vide, le r = E9sultat de ma requ = EAte est vide. Je pense qu'il existe un code pour dire de ne prendre en compte que les combobox non vide, mais je ne sais pas comment faire. Le code sql est le suivant Access Discussions VBA (1) SetFocus (1) Le (1) Salut, J'ai un formulaire avec 6 combobox. Et une requête qui dépend des valeurs de mes combobox. Si je remplis mes 6 combobox, ma requête donne un résultat. Si une de mes combobox est vide, le résultat de
I have to bind the data into combobox from database.In asp.net we can bind data into dropdownlist using datafield and text In windows application to need like this way. You can bind a DataTable to a Combobox to display one value in the ComboBox's list while using another value to identify rows. VB6 provided the ItemData property for ItemData property but allows you to bind almost any type of data object to a ComboBox. This code shows how to bind a DataTable to a ComboBox and display column 1 of the DataTable (the "Description" column) in the ComboBox and use column 2 ("Code") to select ComboBox items. Retrieve the data into a DataSet: Dim strSQL As String = "Select Code, Description From
50 PM how can we make a program in windows application in which take 2-combobox if we select the item of 1st combobox then its subpart is shown in 2nd combobox for example- in 1st list box we select state punjab then its come under districts are shown in 2nd combobox plz help me solve this problem For your example take two combobox control and write following code- / / for binding 1 combobox with country private void DataGrid_Load( object sender, EventArgs e) { getdata(); } / / function for getting country private THIS CODE AND LET ME KNOW. Change in getdata() function, For your example take two combobox control and write following code- / / for binding 1 combobox with country private void DataGrid_Load( object sender, EventArgs e) { getdata(); } / / function for getting country private
I have a userform that includes a combobox which is optional for the user, but if they do use it, they have to user ignores the field, or if they make a selection. They can even click the combobox 'arrow' to see the values and then click to another part of the form without cancel commandbuttons on the form without error. However, the actual behavior is that once the combobox field is entered by the cursor via a mouse click, a selection is required. Attempting to leave the combobox without a selection results in the error "Microsoft Forms: Invalid property value" Is there a different way to set up the combobox that avoids this error? I do not want to offer the user a "blank" value happy if there was a way to block the mouse from selecting (setfocus?) within the combobox as long as they could still select the combobox downarrow and select a value from there. Thank you, Keith Excel Programming Discussions Office (1