473,586 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

text display based on multiple selected

116 New Member
i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id.

its working fine till displaying user names in listbox 2 based on selected of status in listbox. but its not displaying the emailid based on selection of usernames and when i click on search for users button its refreshs the page and shows the intial page also want the text box to be displayed only on click the search for users button

here is the code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //------------------------------------------------------------
  3. // Part 1: Choosing a Status
  4. //============================================================
  5.  
  6. // Initializes a list of acceptable statuses
  7. $statusname_list = array();
  8. $status_list[] = array();
  9.  
  10. $query_status = " SELECT status_type.status, status_type.status_name FROM status_type ";
  11.  
  12.        $result_status = mysql_query($query_status);
  13.         confirm_query($result_status);
  14.  
  15.  
  16.        $statusname_list[]=" ";
  17.   while ($record = mysql_fetch_assoc($result_status)) {
  18.           $statusname_list[] = $record['status_name'] ;
  19.           $status_list[] =  $record['status'];       
  20.         }
  21. $status = $_GET['status_name'];
  22. $user = $_GET['username']
  23.  
  24.  
  25. // A form for choosing the status
  26. ?>
  27. <form method="get" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
  28.     <input type="submit" name="status" value="Search for status:" />
  29.     <select name="status_name" >
  30.         <?php
  31.  
  32.         // Loops through the $status_list array
  33.          foreach ($statusname_list as $value => $option)
  34.         {
  35.             // Sets an attribute to show the chosen status as selected
  36.             $selected = ($status == $value) ? ' selected="selected"' : '';
  37.  
  38.             // Builds an option for each acceptable status
  39.            echo '<option value="'.$value.'"'.$selected.'>'.$option.'</option>';
  40.  
  41.         }
  42.         ?>
  43.     </select>
  44.  
  45.  
  46.     </select>
  47. </form>
  48.  
  49. <?php
  50. //------------------------------------------------------------
  51. // Part 2: Using the Chosen Status to Search the Database
  52. //============================================================
  53.  
  54. // Initializes an empty array of usernames
  55. $usernames = array();
  56.  
  57. // Builds a query to get the names of users with a certain status
  58. $query = "SELECT username FROM users WHERE users.status = '{$status_list[$status]}'";
  59.  
  60. // Executes the query and stores the returned resource in $result
  61. $result = mysql_query($query);
  62.  
  63. // If $result is a resource instead of FALSE...
  64. if ($result)
  65. {
  66.     // Fetches a row until there are no more rows to fetch
  67.     while ($row = mysql_fetch_assoc($result))
  68.     {
  69.         // Stores the username from the fetched row in the $usernames array
  70.         $usernames[] = $row['username'];
  71.     }
  72. }
  73.  
  74. // If there are some usernames in the array...
  75. if (count($usernames) > 0)
  76. {
  77.     ?>
  78.     <p>Users with status: <?php echo $status_list[$status]; ?></p>
  79.     <ul>
  80.     <td>
  81.     <form method="get" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">   
  82.     <input type="submit" name="users" "value="Search for user:" />
  83.     <select name="username" >
  84.         <?php
  85.  
  86.         // Loops through the $status_list array
  87.          foreach ($usernames as $value => $option)
  88.         {
  89.             // Sets an attribute to show the chosen status as selected
  90.             $selected = ($user == $value) ? ' selected="selected"' : '';
  91.  
  92.             // Builds an option for each acceptable status
  93.            echo '<option value="'.$value.'"'.$selected.'>'.$option.'</option>';
  94.  
  95.         }
  96.         ?>
  97.     </select> 
  98.  
  99.  
  100.     </form> 
  101.  
  102.     </td>
  103.  
  104.     </ul>
  105.     <?php
  106. }
  107. else
  108. {
  109.  ?>
  110.  <p>
  111.  <select name="username" >
  112.   <? echo '<option>'." ".'</option>'; ?></p>
  113.  
  114. <?php 
  115. }
  116. ?>
  117.  
  118. <?
  119.  
  120. $query_details = "SELECT emailid FROM users WHERE users.username = '{$usernames[$user]}'";
  121. $result_details = mysql_query($query_details);
  122. if ($result_details)
  123. { $record_details = mysql_fetch_assoc($result_details)
  124.   $emailid[] = $record_details['emailid'];
  125. }
  126.  
  127.  
  128.  
  129. if (count($emailid) > 0)
  130. {?>
  131. <form method="get" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">  
  132. <input type="readonly" name="emailid" "value=<?php $emailid ?> />
  133. </form>
  134. <?
  135. }?>
  136.  
  137.  
May 12 '09 #1
1 2403
angelicdevil
116 New Member
ok i m able to get the fields intact when i click on search for user but the text field still doesnt display the email based on selection here is my code

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. //------------------------------------------------------------
  4. // Part 1: Choosing a Status
  5. //============================================================
  6.  
  7. // Initializes a list of acceptable statuses
  8. $statusname_list = array();
  9. $status_list[] = array();
  10.  
  11. $query_status = " SELECT status_type.status, status_type.status_name FROM status_type ";
  12.  
  13.        $result_status = mysql_query($query_status);
  14.         confirm_query($result_status);
  15.  
  16.  
  17.        $statusname_list[]=" ";
  18.   while ($record = mysql_fetch_assoc($result_status)) {
  19.           $statusname_list[] = $record['status_name'] ;
  20.           $status_list[] =  $record['status'];       
  21.         }
  22. $status = $_GET['status_name'];
  23. $user = $_GET['username'];
  24. $emailid = "" ;
  25.  
  26. // A form for choosing the status
  27. ?>
  28. <form method="get" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
  29.     <input type="submit" name="status" value="Search for status:" />
  30.     <select name="status_name" >
  31.         <?php
  32.  
  33.         // Loops through the $status_list array
  34.          foreach ($statusname_list as $value => $option)
  35.         {
  36.             // Sets an attribute to show the chosen status as selected
  37.             $selected = ($status == $value) ? ' selected="selected"' : '';
  38.  
  39.             // Builds an option for each acceptable status
  40.            echo '<option value="'.$value.'"'.$selected.'>'.$option.'</option>';
  41.  
  42.         }
  43.         ?>
  44.     </select>
  45.  
  46.  
  47.  
  48. <?php
  49.  
  50. // Part 2: Using the Chosen Status to Search the Database
  51. //============================================================
  52.  
  53.  
  54. $usernames = array();
  55. $query = "SELECT username FROM users WHERE users.status = '{$status_list[$status]}'"; 
  56. $result = mysql_query($query);
  57. if ($result)
  58. {
  59.     while ($row = mysql_fetch_assoc($result))
  60.     {
  61.         $usernames[] = $row['username'];
  62.     }
  63. }
  64.  
  65. // If there are some usernames in the array...
  66. if (count($usernames) > 0)
  67. {
  68.     ?>
  69.     <p>Users with status: <?php echo $status_list[$status]; ?></p>
  70.     <ul>
  71.     <td>
  72.  
  73.     <input type="submit" name="users" "value="Search for user:" />
  74.     <select name="username" >
  75.         <?php
  76.  
  77.         // Loops through the $status_list array
  78.          foreach ($usernames as $value => $option)
  79.         {
  80.             // Sets an attribute to show the chosen status as selected
  81.             $selected = ($user == $value) ? ' selected="selected"' : '';
  82.  
  83.             // Builds an option for each acceptable status
  84.            echo '<option value="'.$value.'"'.$selected.'>'.$option.'</option>';
  85.  
  86.         }
  87.         ?>
  88.     </select> 
  89.  
  90.     </td>
  91.  
  92.     </ul>
  93.     <?php
  94. }
  95. else
  96. {
  97.  ?>
  98.  <p>
  99.  <select name="username" >
  100.   <? echo '<option>'." ".'</option>'; ?></p>
  101.  
  102. <?php 
  103. }
  104. ?>
  105.  
  106. <?
  107. // Part 2: Using the Chosen username to Search the Database for emailid
  108. $query_details = "SELECT users.emailid FROM users WHERE users.username = '{$usernames[$user]}' and users.status = '{$status_list[$status]}' ";
  109. $result_details = mysql_query($query_details);
  110. if ($result_details)
  111.   $record_details = mysql_fetch_assoc($result_details);
  112.   $emailid = $record_details['emailid'];
  113.  }
  114.  
  115.  
  116. ?>
  117. <? 
  118. if ($emailid != "") {
  119. ?>
  120.  
  121. <td><input type="disabled" name="emailid" maxlength="30" value="<?php echo $emailid ?>" /></td>
  122. </tr>
  123. <?
  124. }
  125.  
  126. ?>
  127. </form>
  128.  
  129.  
plz help
May 12 '09 #2

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

Similar topics

6
148565
by: Steve Speirs | last post by:
Hi I'm trying to show/hide a simple piece of text and a text field on a form based on what choice is made from a drop down box. <select name="dropdown" size="1"> <option selected value="">Please make a selection</option> <option value="1">Choice 1</option> <option value="2">Choice 2</option> <option value="3">Choice 3</option>
19
6871
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the...
14
2237
by: Norm | last post by:
Hi, Each time the user selects an item from a combobox, I want that string to get appended to the values that were already selected. The result is that the combo is accumulating text each time the user selects an item from its list. I want the delete and backspace keys to function normally, as well as all the other properties of the...
12
1795
by: David | last post by:
Hi, I am trying to achieve the following: 1/ To have a standard form in an asp web page which has various check boxes and radio buttons. As a user selects a form item it updates a text box, of which the contents are submitted to a search page. I know I could just send the form element data to a search page, but in this app, the user is...
14
1893
by: PhilS | last post by:
Hi everybody, I'm new to the forum and Access and hope you can help with the following question using Access 2000: I would like to have a value displayed in a text box based upon two other values. Combo box called Plant - with the following choices Plant 1, Plant 2, Plant 3 Text box - called Cycle Time which is a time field (user input)...
1
2731
by: ArizonaState | last post by:
I have a Stored Proc which outputs the sum of various fields from a table. CODE ... ... COMPUTE SUM(Field1), SUM(Field2), SUM(Field3)... /CODE I am able to execute the SProc and obtain results there, but I would like to display this computed sum in a grid view using the SProc in ASP. Whle I am able to display one record based on a...
2
2122
vikas251074
by: vikas251074 | last post by:
I am creating an application for official use. This application will be used by employees to take items for official use. I have a list, presently this list contains three items - 1) Cartridges, 2) Floppy, 3) CD Note : If a user selects Cartridges then list of printer should display, And if floppy or CD is selected, then 'purpose' text...
0
11583
by: JosAH | last post by:
A Simple Text-Based Menu System Read this this post; there are numerous posts like that: a newbie struggling with some sort of menu implementation. They want nested menus of course and an option to quit the entire thing. Of course they tie their 'business rules' tight together with their (feeble) attempts of their individual menu items and get...
0
7839
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...
0
8202
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
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...
0
8216
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...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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...
1
2345
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
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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...

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.