Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "conn.php";
- //Verifico se chegou parâmetros de pesquisa
- $titulo="";
- $autor="";
- $sql = "select titulo, autor, editora, ano, paginas, categoria from livro where 1=1 ";
- if(isset($_GET['pesquisar'])){
- $titulo=$_GET['titulo'];
- $autor=$_GET['autor'];
- if(!empty($titulo)){
- $sql.=" and titulo like '%$titulo%' ";
- }
- if(!empty($autor)){
- $sql.=" and autor like '%$autor%' ";
- }
- }
- //Busco os dados
- $dados = mysql_query($sql) or die("Erro na pesquisa. Código: $SQL <br/> Erro do banco:". mysql_error());
- ?>
- <html>
- <body>
- <fieldset>
- <legend>Pesquisar:</legend>
- <form name="pesquisa" action="" method="GET">
- Titulo: <input type="text" name="titulo" size="30" value="<?php echo $titulo;?>"/> <br/>
- Autor: <input type="text" name="autor" size="30" value="<?php echo $autor;?>"/><br/>
- <input type="submit" value="Pesquisar" name="pesquisar"/>
- </form>
- </fieldset>
- <hr/>
- <table border="1" width="100%">
- <tr>
- <td><b>Título</b></td>
- <td><b>Autor</b></td>
- <td><b>Editora</b></td>
- <td><b>Ano</b></td>
- <td><b>Páginas</b></td>
- <td><b>Categoria</b></td>
- <td> </td>
- </tr>
- <?php
- while ($row = mysql_fetch_array($dados, MYSQL_ASSOC)) {
- $titulo=$row['titulo'];
- $autor=$row['autor'];
- $editora=$row['editora'];
- $ano=$row['ano'];
- $paginas=$row['paginas'];
- $categoria=$row['categoria'];
- echo "
- <tr>
- <td>$titulo</td>
- <td>$autor</td>
- <td>$editora</td>
- <td>$ano</td>
- <td>$paginas</td>
- <td>$categoria</td>
- <td><img src='alterar.png' width='24' height='24'> <img src='deletar.png' width='24' height='24'></td>
- </tr>";
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement