468,301 Members | 1,402 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

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 2094
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

Post your reply

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

Similar topics

19 posts views Thread by dmiller23462 | last post: by
reply views Thread by JosAH | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.