Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <?php
  2. //database settings
  3. $hostname="localhost";
  4. $database="alex";
  5. $username="root";
  6. $password="";
  7. $mysqli = new mysqli($hostname,$username,$password,$database);
  8.  
  9. //query
  10. $query = "SELECT `useerName FROM `users`";
  11. $result = $mysqli->query($query);
  12.  
  13. //process result
  14. $result_array=array();
  15. while($row = $Result->fetch_assoc())
  16. {
  17. $Result_Array[] = $row;
  18. }
  19. ?>
  20.  
  21. Hope the below code helps:
  22.  
  23. <?php
  24.  
  25. $servername = "localhost";
  26. $username = "your username";
  27. $password = "your password";
  28. $dbname = "your dbname";
  29.  
  30. // Create connection
  31. $conn = mysqli_connect($servername, $username, $password, $dbname);
  32. // Check connection
  33. if (!$conn) {
  34. die("Connection failed: " . mysqli_connect_error());
  35. }
  36. $getname= $_POST['name'];
  37. $sql = "SELECT userName FROM users WHERE userName LIKE '%$getname%';
  38. $result = mysqli_query($conn, $sql);
  39.  
  40. if ($result->num_rows > 0) {
  41. echo "<table><tr><th>Name</th></tr>";
  42. // output data of each row
  43. while($row = $result->fetch_assoc()) {
  44. echo "<tr><td>" . $row["userName"]. "</td></tr>";
  45. }
  46. echo "</table>";
  47. } else {
  48. echo "0 results";
  49. }
  50.  
  51. mysqli_close($conn);
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement