473,225 Members | 1,390 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,225 software developers and data experts.

text display based on multiple selected

116 100+
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 2367
angelicdevil
116 100+
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
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...
19
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...
14
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...
12
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,...
14
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....
1
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...
2
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, ...
0
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...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.