Guest User

Display search results on the same page in a table with PHP

a guest
Mar 16th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  8. <!-- Bootstrap -->
  9. <link href="css/bootstrap.min.css" rel="stylesheet">
  10. <link href="css/style.css" rel="stylesheet">
  11. </script>
  12. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  13. <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  14. <!--[if lt IE 9]>
  15. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  16. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  17. <![endif]-->
  18. </head>
  19. <body>
  20. <h3 style="color:white;">Search CRF:</h3>
  21.  
  22. <?php
  23. $servername = "localhost";
  24. $username='root';
  25. $password = "";
  26. $dbname = "official_db";
  27.  
  28. $mysqli = new mysqli($servername,$username, Null, $dbname);
  29. if ($mysqli->connect_error) {
  30. die("Connection failed: " . $mysqli->connect_error);
  31. }
  32. ?>
  33.  
  34. <form id="searchform" method="post" action = '' target="search.php">
  35. <input id="Cref" style="height: 25px; width: 140px; position: fixed; top: 150px; left: 50px" name="name" type="text" >
  36.  
  37. <input type="submit" value="Search" class="btn btn-primary btn" style="color: white; font-style: normal; background-color: blueviolet; position: fixed; top: 148px; left: 220px">
  38.  
  39. </form>
  40.  
  41. <?php
  42. $name = '';
  43. if(! get_magic_quotes_gpc() ) {
  44. $name = isset($_POST['name']) ? trim( addslashes($_POST['name'])) : '';
  45. }else {
  46. $name = isset($_POST['name']) ? trim($_POST['name'])) : '';
  47. }
  48. session_start();
  49. $results="SELECT * FROM tbl WHERE Name LIKE '%$name%'";
  50. $resultSet = $mysqli->query($results);
  51. $numRows = $resultSet->num_rows;
  52.  
  53. if ($numRows < 0) {
  54. echo "No Results";
  55. }
  56. else
  57. {
  58. ?>
  59. <div class="col-md-6 col-md-offset-6">
  60. <table class="table table-hover" style='background-color:antiquewhite'>
  61. <thead>
  62. <tr>
  63. <th style="color: black;">NAme</th>
  64. <th style="color: black;">Address</th>
  65. <th style="color: black;">County</th>
  66. </tr>
  67. </thead>
  68. <tbody>
  69. <?php
  70. while ($row = $resultSet->fetch_object()) {
  71. ?>
  72. <tr>
  73. <td><?php echo "{$row->CRF} " ?></td>
  74. <td><?php echo "{$row->Host} " ?></td>
  75. <td><?php echo "{$row->Description} " ?></td>
  76. </tr>
  77. <?php }
  78.  
  79. ?>
  80. </tbody>
  81. </table>
  82. <div>
  83. <?php
  84.  
  85. }
  86. ?>
  87.  
  88. <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  89. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  90. <!-- Include all compiled plugins (below), or include individual files as needed -->
  91. <script src="js/bootstrap.min.js"></script>
  92. </body>
  93. </html>
Add Comment
Please, Sign In to add comment