Guest User

Untitled

a guest
Oct 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <?php
  2. $conn = mysqli_connect('localhost','root','' , 'selecttest') ;
  3.  
  4. $query = "SELECT DISTINCT username FROM users";
  5. $result = mysqli_query($conn,$query);
  6.  
  7.  
  8. ?>
  9. <!DOCTYPE html>
  10. <html>
  11. <head>
  12. <title>Select</title>
  13. </head>
  14. <body>
  15.  
  16. <?php
  17.  
  18. $query1 = "SELECT * FROM users ";
  19. $result1 = mysqli_query($conn,$query1);
  20. echo "<table>
  21. <tr>
  22. <th>first name</th>
  23. <th>last name</th>
  24. </tr>
  25. ";
  26. while ($row = mysqli_fetch_assoc($result1)){
  27. $first = $row['first'];
  28. $last = $row['last'];
  29. echo "<tr>
  30. <td>$first</td>
  31. <td>$last</td>
  32. </tr>";
  33. }
  34. echo "</table>";
  35.  
  36.  
  37. $op = $_POST['op'];
  38. if (isset($_POST['ok'])) {
  39. $query2 = "SELECT * FROM users WHERE username = '$op'";
  40. $result2 = mysqli_query($conn,$query2);
  41. echo "<table>
  42. <tr>
  43. <th>first name</th>
  44. <th>last name</th>
  45. </tr>
  46. ";
  47. while ($row = mysqli_fetch_assoc($result2)){
  48. $first = $row['first'];
  49. $last = $row['last'];
  50. echo "<tr>
  51. <td>$first</td>
  52. <td>$last</td>
  53. </tr>";
  54. }
  55. }
  56. echo "</table>";
  57. ?>
  58. <form method="POST" action="">
  59. <select name="op">
  60. <?php
  61. while ($row = mysqli_fetch_assoc($result)) {
  62. $user = $row['username'];
  63. echo "
  64. <option>$user</option>
  65. ";
  66. }
  67. ?>
  68. </select>
  69. <input type="submit" name="ok">
  70. </form>
  71. </body>
  72. </html>
Add Comment
Please, Sign In to add comment