hi
I have two listboxes, if i select an item from first listbox relative items(fetching from database) of selected item should be loaded into second listbox. how we can solve this problem in php.
one thing i already got the above result using php + javascript.
i need the code which is written purely in PHP without using javascript, is it possible?
regards,
Shiva
1 7573 Atli 5,058
Recognized Expert Expert
Yes, it is indeed possible.
You can simply populate your first list-box in any way you see fit and instruct it, via the 'onChange' event to submit the form. The form's action property would point to the very page it is on, causing the page to refresh and the data to be sent along for the ride.
The you can simply have you PHP code check if the first box has a value and populate your second box based on the value of the first box.
This example is quite static, but shows what I mean. You will of course have to replace the huge array of data with data from whatever source you get your data from and modify the foreach() loops accordingly. -
<?php
-
// Get the values of the list-boxes
-
$firstBox = @$_POST['firstBox'];
-
if(empty($firstBox))
-
$firstBox = "first";
-
$secondBox = @$_POST['secondBox'];
-
if(empty($secondBox))
-
$secondBox = "first";
-
-
// Print the form header
-
echo '<form action="?" method="POST">';
-
-
// Crete the data for the boxes
-
// Note, this will most likely be
-
// replace by your date, however you get it.
-
$boxData = array(
-
"first" => array(
-
"Title" => "First",
-
"Value" => "first",
-
"Data" => array(
-
"first" => "First of the first",
-
"second" => "Second of the first",
-
"third" => "Third of the first"
-
)
-
),
-
"second" => array(
-
"Title" => "Second",
-
"Value" => "second",
-
"Data" => array(
-
"first" => "First of the second",
-
"second" => "Second of the second",
-
"third" => "Third of the second"
-
)
-
)
-
);
-
-
// Print the first box
-
echo '<select name="firstBox" onChange="submit();">';
-
foreach($boxData as $v) {
-
$selected = "";
-
if($v['Value'] == $firstBox) $selected = " selected";
-
echo ' <option value="'. $v['Value'] .'"'. $selected .'>'. $v['Title'] .'</option>';
-
}
-
echo '</select>';
-
-
// Print the second box
-
echo '<select name="secondBox" onChange="submit();">';
-
foreach($boxData[$firstBox]['Data'] as $k => $v) {
-
$selected = "";
-
if($k == $secondBox) $selected = " selected";
-
echo ' <option value="'. $k .'"'. $selected .'>'. $v .'</option>';
-
}
-
echo '</select>';
-
-
-
// Close the form
-
echo '</form>';
-
-
// Show the selected boxes
-
echo "<p>You have selected: $firstBox > $secondBox </p>";
-
?>
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: amber |
last post by:
Hello.
Can someone tell me what I may be doing wrong here?
I'm using the code (lboxRP is a listbox):
Dim newRPindex As Integer
newRPindex = Me.lboxRP.FindString(RP)
Me.lboxRP.SetSelected(newRPindex, True)
When the last line executes, I get an error message:
|
by: Paul T. Rong |
last post by:
I have a listbox (of product names) control on my form. I want to pass the
selected item (a product name) to a subform, and the product unitprice
should apear automatically next to the product name in the subform. Is it
possible? How do I do this? Thanks in advance.
Paul from Slovakia
|
by: Oddball |
last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler.
What I want to draw as the item is another control. I have created a user control that I
would like to list in this listbox but I can't for the life of me figure out how to draw the
control inside ListBox...
I get as far as:
private void lbImageList_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
|
by: collie |
last post by:
Hi,
I have 2 listboxes. The first gets populated from the db as soon as
the page loads. The second listbox get populated based on the user's
selection from the first listbox. However, currently the code is
such that with each selection there is a postback. We want to avoid it
using filter and javascript. I am not using ADO.NET but adodbc and no
datagrids or datasets (please don't tell me that i should as my boss
clearly doesn't want...
|
by: Chris Leuty |
last post by:
I am populating a multiselect Listbox from a dataset, with the content of
the listbox filled by one table, and the selections determined from another
table. So far, I have been keeping the dataset a denormalized mirror of the
database, but I'm not having much luck getting the selection logic down (I
haven't found a 'hook' where I can access the listbox object as an object to
set the listitem's selected property before it gets rendered)..
...
| |
by: yamne |
last post by:
I have a problem.
When I click in edit datagrid button I show two listbox and two button.
I use two button to move data between two listbox.
My problem is that I can't call the listbox in the button_click function
because the only way to find the listbox is:
(listbox)e.item.findcontrol
What s the solution to this problem?
|
by: Dave |
last post by:
Hi all,
After unsuccessfully trying to make my own dual listbox control out of
arraylists, I decided to look for a 3rd party control. I've looked for over
a week now and can't find anything but ASP.Net stuff when I need a Windows
Form control. I've seen dual listbox populators in countless Windows
applications, and have seen them run very fast, so I figured this would be
extremely popular.
Here's how it should work:
|
by: Ali Chambers |
last post by:
Hi,
I have created a listbox called "dtlist1" on my VB.NET form. I call a
procedure as follows:
Private Sub openfile(flname As String)
dtlist1.Items.Clear()
etc..
|
by: Sunray |
last post by:
I have a form called the sales form and i have 2 sets of listboxes
So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set.
when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
|
by: Academia |
last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it
there.)
I have a listbox populated with Objects.
The Class has a String field that ToString returns.
I assume that is what the ListBox uses for its display. Correct?
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |