473,387 Members | 1,705 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,387 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 2381
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
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...

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.