Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $conn = mysqli_connect('localhost','root','' , 'selecttest') ;
- $query = "SELECT DISTINCT username FROM users";
- $result = mysqli_query($conn,$query);
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Select</title>
- </head>
- <body>
- <?php
- $query1 = "SELECT * FROM users ";
- $result1 = mysqli_query($conn,$query1);
- echo "<table>
- <tr>
- <th>first name</th>
- <th>last name</th>
- </tr>
- ";
- while ($row = mysqli_fetch_assoc($result1)){
- $first = $row['first'];
- $last = $row['last'];
- echo "<tr>
- <td>$first</td>
- <td>$last</td>
- </tr>";
- }
- echo "</table>";
- $op = $_POST['op'];
- if (isset($_POST['ok'])) {
- $query2 = "SELECT * FROM users WHERE username = '$op'";
- $result2 = mysqli_query($conn,$query2);
- echo "<table>
- <tr>
- <th>first name</th>
- <th>last name</th>
- </tr>
- ";
- while ($row = mysqli_fetch_assoc($result2)){
- $first = $row['first'];
- $last = $row['last'];
- echo "<tr>
- <td>$first</td>
- <td>$last</td>
- </tr>";
- }
- }
- echo "</table>";
- ?>
- <form method="POST" action="">
- <select name="op">
- <?php
- while ($row = mysqli_fetch_assoc($result)) {
- $user = $row['username'];
- echo "
- <option>$user</option>
- ";
- }
- ?>
- </select>
- <input type="submit" name="ok">
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment