hi every one im using php for developing a project.
now im having big problem,
i have three drop down lists(lets say DD1,DD2,DD3) they will show item from database.
for example DD1 have(it will load from database AND DD2,DD3 remain empty @ beginning) Books,Cars,Films.
assume that i have selected Cars then DD2 have to show Sports car, Regular cars,..ect.
Like that if i select an item from DD2 the DD3 should change according to that.
can anyone explain how can i complete this task???
thanks in advance.
9 6940
hi every one im using php for developing a project.
now im having big problem,
i have three drop down lists(lets say DD1,DD2,DD3) they will show item from database.
for example DD1 have(it will load from database AND DD2,DD3 remain empty @ beginning) Books,Cars,Films.
assume that i have selected Cars then DD2 have to show Sports car, Regular cars,..ect.
Like that if i select an item from DD2 the DD3 should change according to that.
can anyone explain how can i complete this task???
thanks in advance.
You'd use an ajax call to query a seperate php page and then have the results of the php page populate the drop down.
You'll have to read a tutorial on ajax - w3schools has a good one
thanks markusn00b,
but i dont have any idea about AJAX & i didnt use any coding in AJAX.
cant it done by php itself?
Atli 5,058
Expert 4TB
Hi.
PHP can not edit anything client-side once the page has been loaded. So, it can't be used to respond to any client-side events, such as drop-down changes.
Markus' suggestion would be my nr. 1 solution as well. It simply makes a HTTP request, requesting additional data from a PHP document. (See w3schools.com for a simple AJAX tutorial)
You could of course have PHP create a Javascript array, containing the data, and have Javascript switch out the data when the drop-down boxes change. I wouldn't advice this tho if you have loads of data to handle, the AJAX solution would be better.
thanks markusn00b,
but i dont have any idea about AJAX & i didnt use any coding in AJAX.
That is why you read tutorials.
Regards.
Doh to me. All the time I have been reading everyone's jibe about Ajax and not knowing what in the world this is. So I took a look to see just now.
You can do the very same thing (maybe with a bit more coding effort on your part) by just including a hidden iframe on your main page calling its own separate php scripts that do all your behind the scenes database queries and other tasks. So if you really do not wish to get into Ajax, just use a combo of a hidden iframe and some javascript to do needed behind the scenes queries and repopulations of main page drop down lists.
There is also another way to handle the parent -> child drop down list thing, which does not require background queries and which I use a lot in my application. You basically get all the possible information for the drop down lists from the database when you present the main page, and store them in javascript arrays, and then let javascript repopulate the drop down lists using the "onchange" event. This works well when the number of choices and number of lists in the chain are not too large. It then does not require any client server interaction (and avoids that latency) when the user is clicking around in the lists. To set this up does require a bit of javascript but it works nicely. If you would use this often, you can create some PHP class that creates and manages the creation of HTML and Javascript code for parent->child or parent->child->child lists. I did this some time back and now it is a breeze for me to include a new one on a new page.
-
<!--
-
----------------------------
-
database: demo1;
-
table: demo_table;
-
fields(demo_table)
-
item varchar(20);
-
list varchar(20);
-
----------------------------
-
-->
-
<html>
-
<head>
-
<title>Untitled Document</title>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-
<script type="text/javascript">
-
function getItem(sel)
-
{
-
var itemCode = sel.options[sel.selectedIndex].value;
-
//alert(itemCode);
-
var url= "http://localhost/onchange1.php?item="+itemCode;
-
window.location=url;
-
-
}
-
-
</script>
-
</head>
-
-
<body>
-
-
<form action="" method="post">
-
<table>
-
<tr>
-
<td>Item </td>
-
<td><select id="item" name="item" onchange="getItem(this)">
-
<option value="">Select </option>
-
<option value="pr">Printer</option>
-
<option value="ri" >Ribbon</option>
-
</select>
-
</td>
-
</tr>
-
<tr>
-
<td>List </td>
-
<td><select id="item_list" name="item_list" >
-
<option value="">Select </option>
-
<?php
-
$i_code=$_REQUEST['item'];
-
-
$con = mysql_connect("localhost","root","");
-
mysql_select_db("demo1",$con);
-
-
$query="select list from demo_table where item='$i_code'";
-
$res=mysql_query($query);
-
$num=mysql_num_rows($res);
-
for($i=0;$i<$num;$i++)
-
{
-
$data=mysql_fetch_array($res);
-
$v=$data[0].$i;
-
echo "<option value='$data[0]'>".$data[0]."</option>";
-
}
-
?>
-
</select>
-
</td>
-
</tr>
-
</table>
-
</form>
-
</body>
-
</html>
-
Atli 5,058
Expert 4TB
Hi,sethupnr.
Please use [code] tags when posting code examples. Failing to do so will make your code next to unreadable and adds extra work for us moderators who have to clean up after you.
[code] ...Code goes here... [/code]
[code=php] ...PHP code goes here... [/code]
Thank you.
hi thanks for reply to my problem.
special thanks to sethupnr its very useful to me as a begginner. and also thanks to markusn00b, for gude me to study about AJAX.
thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul M |
last post by:
Hi folks,
When I set the datasource of a dropdown list and bind it, the drop down list
always defaults to the first item in the list. I need it to default to
Nothing or NULL or whatever it is...
|
by: Merdaad |
last post by:
My drop down list is populated from a static array in my codebehind (c#)
code.
I set the selected index based on some known values(from DB), when the
screen shows up, dropdown list shows that the...
|
by: Yoshitha |
last post by:
hi
I have 2 drop down lists in my application.1st list ontains itmes like
java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the
items like 50,60,70,80,90,100.
i will...
|
by: BryanS |
last post by:
I am having trouble trying to link 2 drop down lists and
a repeater control. What i want is 2 drop down lists, the
first being a list of food categories. When a category is
selected the second...
|
by: Rob Meade |
last post by:
Hi all,
Looking for a bit of help if possible.
For about 2 weeks now I've been investigating the best way to populate
related drop down menus, and have their values pre-populated again if the...
|
by: zacks |
last post by:
I have an application I am developing that has a Combo Box that is
intended to show a list of available tables in the selected DSN. I
have put code in the control's DropDown event handler to clear...
|
by: Valli |
last post by:
Hi,
I need to populate a dropdownlist control with values. Number of items for
that list exceeds 100.
I am using Html select list option.
When I drop down the list control, it shows the item...
|
by: tokcy |
last post by:
Hi everyone,
I am new in php and ajax, i am facing the prob while i click on element of first drop down then in second dropdown all element showl come from database.
I mean i have three dropdown 1....
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |