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
- <?php
- //------------------------------------------------------------
- // Part 1: Choosing a Status
- //============================================================
- // Initializes a list of acceptable statuses
- $statusname_list = array();
- $status_list[] = array();
- $query_status = " SELECT status_type.status, status_type.status_name FROM status_type ";
- $result_status = mysql_query($query_status);
- confirm_query($result_status);
- $statusname_list[]=" ";
- while ($record = mysql_fetch_assoc($result_status)) {
- $statusname_list[] = $record['status_name'] ;
- $status_list[] = $record['status'];
- }
- $status = $_GET['status_name'];
- $user = $_GET['username']
- // A form for choosing the status
- ?>
- <form method="get" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
- <input type="submit" name="status" value="Search for status:" />
- <select name="status_name" >
- <?php
- // Loops through the $status_list array
- foreach ($statusname_list as $value => $option)
- {
- // Sets an attribute to show the chosen status as selected
- $selected = ($status == $value) ? ' selected="selected"' : '';
- // Builds an option for each acceptable status
- echo '<option value="'.$value.'"'.$selected.'>'.$option.'</option>';
- }
- ?>
- </select>
- </select>
- </form>
- <?php
- //------------------------------------------------------------
- // Part 2: Using the Chosen Status to Search the Database
- //============================================================
- // Initializes an empty array of usernames
- $usernames = array();
- // Builds a query to get the names of users with a certain status
- $query = "SELECT username FROM users WHERE users.status = '{$status_list[$status]}'";
- // Executes the query and stores the returned resource in $result
- $result = mysql_query($query);
- // If $result is a resource instead of FALSE...
- if ($result)
- {
- // Fetches a row until there are no more rows to fetch
- while ($row = mysql_fetch_assoc($result))
- {
- // Stores the username from the fetched row in the $usernames array
- $usernames[] = $row['username'];
- }
- }
- // If there are some usernames in the array...
- if (count($usernames) > 0)
- {
- ?>
- <p>Users with status: <?php echo $status_list[$status]; ?></p>
- <ul>
- <td>
- <form method="get" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
- <input type="submit" name="users" "value="Search for user:" />
- <select name="username" >
- <?php
- // Loops through the $status_list array
- foreach ($usernames as $value => $option)
- {
- // Sets an attribute to show the chosen status as selected
- $selected = ($user == $value) ? ' selected="selected"' : '';
- // Builds an option for each acceptable status
- echo '<option value="'.$value.'"'.$selected.'>'.$option.'</option>';
- }
- ?>
- </select>
- </form>
- </td>
- </ul>
- <?php
- }
- else
- {
- ?>
- <p>
- <select name="username" >
- <? echo '<option>'." ".'</option>'; ?></p>
- <?php
- }
- ?>
- <?
- $query_details = "SELECT emailid FROM users WHERE users.username = '{$usernames[$user]}'";
- $result_details = mysql_query($query_details);
- if ($result_details)
- { $record_details = mysql_fetch_assoc($result_details)
- $emailid[] = $record_details['emailid'];
- }
- if (count($emailid) > 0)
- {?>
- <form method="get" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
- <input type="readonly" name="emailid" "value=<?php $emailid ?> />
- </form>
- <?
- }?>