473,385 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Importing data into combo box

51
Hi,
i have a mysql database 'country_list' which consist of two entity- one is country_code another is country_name.now i need to import all the country_code into a combo box and when a user will select a country code the respective country name will be displayed into a text box. how can i do that?

waiting for ur reply.

thanks
Mainul
Dec 5 '06 #1
3 3093
Hai Using ajax concept

[PHP]
file name:country_code.php
<?
$connect=mysql_connect("localhost","root","");
$select_db=mysql_select_db("country",$connect);
?>
<SCRIPT LANGUAGE="JavaScript">
<!--
var req
function gettest(key)
{
//alert(key);
req = GetXmlHttpObject();
req.open('POST','getdatbase.php', false);
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
//req.onreadystatechange=stateChanged
req.send('ids='+key);
if(req.status == 200)
document.getElementById("rr").value=req.responseTe xt;
// document.getElementById("r").innerHTML=req.respons eText;
}
function stateChanged()
{
/*if (req.readyState==0)
{
//alert("loding");
document.getElementById('content').innerHTML=""
}
else if (req.readyState==1)
{
//alert("loding");
document.getElementById('content').innerHTML="LOAD ING"
}
else if (req.readyState==4)
{
//alert("loding");
document.getElementById('content').innerHTML="comp leted"
}*/
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
//-->
</SCRIPT>

<table align=center width=80% border=1>
<form name=test method=post action="">
<tr><td>Select Country name</td><td><select name="country" onChange="gettest(this.value)">
<?
$select_value="Select * from coun";
$exexute_quey=mysql_query($select_value);
$num_rows=mysql_num_rows($exexute_quey);
for($i=0;$i<$num_rows;$i++)
{
$getdata=mysql_fetch_array($exexute_quey);
$country_code=$getdata['cid'];
$country_name=$getdata['cname'];
?>
<option value=<?=$country_code?>><?=$country_name?></option>
<?
}
?>
</select>
</td></tr>
<tr><td>Country name</td><td><input type=text id="rr" ></tr>
<tr><td><span id="r"></span></td></tr>
<tr><td colspan=1><input type=submit name=sub value=submit></td>
</form>
</table>


filename:getdatbase.php
<?
$connect=mysql_connect("localhost","root","");
$select_db=mysql_select_db("country",$connect);
$couid=$_REQUEST['ids'];
$select_value="Select * from coun where cid=$couid";
$exexute_quey=mysql_query($select_value);
$getdata=mysql_fetch_array($exexute_quey);
echo $countryname=$getdata['cname'];
?>
[/PHP]
Dec 5 '06 #2
ronverdonk
4,258 Expert 4TB
This looks like a simple problem with a simple solution. I believe Ajax is useful, but not a cure for all ailments and certainly not in this case.

There is (a) a 1-1 relation between the country code and the country name and (b) you display all the country codes already in the box, so there is no need for any fancy and heavy solution. You can use a simple dropdown box that holds all data.

Make one drop down select box with the country name as the value and the country code as the text part of the option. As follows:
Expand|Select|Wrap|Line Numbers
  1. <option value='country_name'>country_code</option>
The user selects the country code presented to him/her and the value of the selected box (i.e. country_name) is passed to you and you can display it onto the screen.

Ronald :cool:
Dec 5 '06 #3
mainul
51
hello guys thank you for your solutions
Dec 7 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: steve | last post by:
Hi, I have researched but have not found a good solution to this problem. I am importing large amounts of data (over 50 Meg) into a new mysql db that I set up. I use >mysql dbname <...
12
by: expect | last post by:
What's the big deal with importing text files? I have a 70 MB file to import and it's been one problem after another. I used the copy command and it appears that it's just not possible. I finally...
11
by: Grim Reaper | last post by:
I am importing a .csv file into Access that has 37 fields. My problem is that sometimes the last field only has data at the end of the column (it looks like when you import a file into Access, for...
7
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
1
by: Donna Sabol | last post by:
I have a form (frm_MAIN_RPT) that contains a combo box (Combo6) & subform (dbo_REQ_subform). The combo box is used to select the "cost center" data that will be displayed in the subform. From...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
3
by: rlm | last post by:
This small problem to solve involves a two table database (one parent and one child table), one winform and two combo boxes. Combo box A is populated in the Load event. Combo box A pulls data...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
1
by: hexagram | last post by:
hi guys can anybody can teach me how to do this scenario Transfering Data of a form to a new form The Scenario is: I have a Delivery Receipt Form (Hardware) with a fields of the following ...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.