473,289 Members | 2,108 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,289 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 2374
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...
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.