473,624 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

To access the data from database when select the value in dropdown menu

99 New Member
Hi to all, i m newer to this site and fresher in Ajax world. Actually i get a problem while accessing data from Database. I have a combo box in my pages. Actually i want to access data from the database and put in a form variable as soon as when i select the name in the combo box. For more details i m giving the code below..
this is my first pages: empAttedence.ph p
Expand|Select|Wrap|Line Numbers
  1. <table width="100%" cellpadding="2" cellspacing="1">
  2.  
  3. <form name="attendence" method="post" action="attendence.php">
  4. <tr >
  5. <td align="left" width="40%">
  6.     Employee Name:
  7. </td>
  8. <td align="left">
  9. <?php 
  10.  
  11.  
  12.         $empDepartment = $_GET['empDepartment'];
  13.  
  14.         $sql1 = "SELECT * FROM employee WHERE empDepartment='$empDepartment'";
  15.         $result = mysql_query($sql1) or die(mysql_error());
  16. ?>
  17.     <select name="empFirstName">
  18. <?php
  19.         while($rows = mysql_fetch_array($result))
  20.  
  21.         {
  22. ?>
  23.  
  24.         <option value="<?php echo $rows['empFirstName']; ?>"><?php echo $rows['empFirstName']; ?></option>
  25.  
  26. <?php
  27.         }
  28. ?>
  29. </select>
  30. <?php 
  31.     $sql1 = "SELECT * FROM employee WHERE empDepartment='$empDepartment'";
  32.     $result = mysql_query($sql1) or die(mysql_error());
  33.     $rows = mysql_fetch_array($result) or die(mysql_error());
  34. ?>
  35. <input type="hidden" value="<?php echo $rows['empId']; ?>" name="empId">
  36. <input type="hidden" value="<?php echo $rows['empDepartment']; ?>" name="empDepartment">
  37. <input type="hidden" value="<?php echo $rows['empLastName']; ?>" name="empLastName">
  38.  
  39. </td>
  40. </tr>
  41. <tr>
  42.     <td align="left">Date:</td>
  43.     <td align="left"><input type="text" value="<?php echo date("Y-m-d");?>" name="empAttendenceDate" size="10">&nbsp&nbsp(YYYY-MM-DD)</td>
  44. </tr>
  45. <tr>
  46.     <td align="left">
  47.         In-Time:
  48.     </td>
  49.     <td align="left">
  50.         <input type="text" name="empInTime" size="10">&nbsp (9.30)
  51.     </td>
  52. </tr>
  53. <tr>
  54.     <td align="left">
  55.         Out-Time:
  56.     </td>
  57.     <td align="left">
  58.         <input type="text" name="empOutTime" size="10"> &nbsp(6.30)
  59.     </td>
  60. </tr>
  61. <tr>
  62.     <td></td>
  63.     <td align="left"><input type="submit" value="Submit" name="submit">&nbsp&nbsp<input type="reset" value="Reset" name="reset"></td>
  64. </tr>
  65.  
  66. </form>
  67. </table></b>
  68. Actually when I select the name in 
  69. <select name="empFirstName">
  70. <?php
  71.         while($rows = mysql_fetch_array($result))
  72.  
  73.         {
  74. ?>
  75.  
  76.         <option value="<?php echo $rows['empFirstName']; ?>"><?php echo $rows['empFirstName']; ?></option>
  77.  
  78. <?php
  79.         }
  80. ?>
  81. </select>
the data in the row should access automatically through ajax. Plz if you know then please help as soon as possible. I want to pass the other data through other pages as hidden value. Thanking you and waiting for you reply
Oct 16 '07 #1
1 1861
acoder
16,027 Recognized Expert Moderator MVP
The PHP code that retrieves the data should be put in a separate file. This should then be called via AJAX. See an example.
Nov 3 '07 #2

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

Similar topics

1
3354
by: djharrison | last post by:
I'm new to ASP and database programming but I am trying to connect to a database using a concatenation of a strings and a menu item from a form. Ok here's what I have... an asp form that has a dropdown menu list that finds *.mdb files in the current folder. It also has a 'Select' button on it. I want the user click select and either in this page or another (not sure which is best?) make a connection to the database using the strPath...
1
10064
by: Rod Early | last post by:
I need to know when the select element's dropdown list is opened (as when the user clicks on the arrow or does ALT-downarrow from the keyboard). Similarly, I need to known when the dropdown list closes. The closing of the dropdown list can happen without changing the dropdown, hence the onchange event is not a sure way to determine that the dropdown list closed. Is this possible in Internet Explorer?
4
2064
by: Odin | last post by:
Hello I am making a webpage with two dropdown menus. First I have a dropdown menu with a list of 235 countries. When one country is selected from this list the contents of the next dropdown menu is decided from a coresponding file containing a huge amount of cities. The biggest of these files being 6 MB. Getting different advices I have now to different sets of code doing this thing. Does anyone know if any of these two sets of code is...
13
3976
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate button "Unexpected Error":3251 operation is not supported for this type of object.The demo cd has two databases, one is called inventory and the other just has the tables for the design called inventory data. When you run inventory the database works...
27
45536
by: Wayne | last post by:
I've been clicking around Access 2007 Beta 2 and can't see the custom menu bar designer. Is it in the beta? Maybe I'm blind. The question that comes to mind is: Will custom menu bars be the same height as they were in previous versions or will they be the "ribbon" style that takes up a huge portion of the screen? Also when I use Access 2007 to open an Access 2003 database that has custom menu bars they display as they did in Access...
3
2145
by: Eric Layman | last post by:
HI, I have a select menu <select id="country" runat="server" class="myformat "> <option value="AFGHANISTAN">AFGHANISTAN</option> <option value="ALBANIA">ALBANIA</option>
1
2317
akhan
by: akhan | last post by:
i used the following code to enter data in dropdown menu : <? $con=mysql_connect("","",""); mysql_select_db('investment',$con); $query="select *from personal_info"; $res = mysql_query($query); echo '<label>Select</label>'; echo '<select id="id" name="val">';
5
3994
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make Fields Names: countrycode, make
2
19450
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
8236
marktang
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...
0
8173
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8475
tracyyun
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...
1
6110
isladogs
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...
0
5563
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();...
0
4079
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...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
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...

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.