Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <?php
  2. header('Content-type: text/html; charset=utf-8');
  3. $pesquisa = ($_REQUEST["q"]) ? $_REQUEST["q"] : '';
  4. if (strlen($pesquisa) == 0) {
  5. exit;
  6. }
  7. $ligacao = mysql_connect('localhost', 'root', 'flag');
  8. if (!$ligacao) {
  9. die('Não foi possível conetar ao MySQL: ' . mysql_error() . "<br/>");
  10. }
  11. $ligacao_bd = mysql_select_db('sex_shop');
  12. if (!$ligacao_bd) {
  13. die('Não consegui seleccionar a BD sex_shop: ' . mysql_error() . "<br/>");
  14. }
  15. mysql_set_charset('utf8');
  16. $resultado = mysql_query(
  17. "select * from PRODUTOS where upper(NOME) like upper('%" . $pesquisa . "%') or upper(DESCRICAO) like
  18. upper('%" . $pesquisa . "%') order by DESCRICAO");
  19. if (!$resultado) {
  20. echo "Erro na pergunta SQL " . mysql_error() . "<br/>";
  21. exit;
  22. }
  23.  
  24. //verificar quantidade de registos obtidos
  25. $qtd_linhas = mysql_num_rows($resultado);
  26.  
  27. if ($qtd_linhas > 0) {
  28. ?>
  29. <br/>
  30. <table border="0" cellcellpadding="0" cellspacing="0">
  31. <?php
  32. while ($linha = mysql_fetch_assoc($resultado)) {
  33. echo "<tr><td>" . str_ireplace($pesquisa, "<b>" . $pesquisa . "</b>", $linha["Nome"]) . "</td>";
  34. echo "<td>" . str_ireplace($pesquisa, "<b>" . $pesquisa . "</b>", $linha["Descricao"]) . "</td>";
  35. }
  36. ?>
  37. </table>
  38. <?php
  39. }
  40. mysql_close($ligacao);
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement