Advertisement
nelsonchalid

pesquisa

May 19th, 2022
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php
  2.  
  3. include('conexao2.php');
  4.  
  5. ?>
  6. <!DOCTYPE html>
  7. <html lang="pt-br">
  8. <head>
  9.     <meta charset="UTF-8">
  10.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  11.     <meta name="viewport" content="width=device-width, initial-scale=1.0">    
  12.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  13.     <title>Sistema de Busca</title>
  14. </head>
  15. <body>
  16.     <div class="container">
  17.     <br><br>
  18.     <h1>Pesquisa de Links</h1>
  19.     <form action="">
  20.         <input name="busca" size="64" value="<?php if(isset($_GET['busca'])) echo $_GET['busca']; ?>" placeholder="O que você deseja pesquisar?" type="text">
  21.         <button type="submit">Pesquisar</button>
  22.     </form>
  23.     <br>
  24.     <table width="600px" border="1">
  25.         <tr>
  26.             <th>Nome</th>
  27.             <th>url</th>
  28.             <th>Data de cadastro</th>
  29.         </tr>
  30.         <?php
  31.         if (!isset($_GET['busca'])) {
  32.             ?>
  33.         <tr>
  34.             <td colspan="3">Digite algo para pesquisar...</td>
  35.         </tr>
  36.         <?php
  37.         } else {
  38.             $pesquisa = $mysqli->real_escape_string($_GET['busca']);
  39.             $sql_code = "SELECT *
  40.                FROM url
  41.                WHERE nome LIKE '%$pesquisa%'
  42.                OR palavras_chave LIKE '%$pesquisa%'";
  43.             $sql_query = $mysqli->query($sql_code) or die("ERRO ao consultar! " . $mysqli->error);
  44.            
  45.             if ($sql_query->num_rows == 0) {
  46.                 ?>
  47.             <tr>
  48.                 <td colspan="3">Nenhum resultado encontrado...</td>
  49.             </tr>
  50.             <?php
  51.             } else {
  52.                 while($dados = $sql_query->fetch_assoc()) {
  53.                     ?>
  54.                     <tr>
  55.                         <td><?php echo $dados['nome']; ?></td>
  56.                         <td><?php echo $dados['url']; ?></td>
  57.                         <td><?php echo $dados['data']; ?></td>
  58.                     </tr>
  59.                     <?php
  60.                 }
  61.             }
  62.             ?>
  63.         <?php
  64.         } ?>
  65.     </table>
  66.     <br><br>
  67.     <a href="index.php">Voltar para o início</a>
  68.     </div>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement