Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-type: text/html; charset=utf-8');
- $pesquisa = ($_REQUEST["q"]) ? $_REQUEST["q"] : '';
- if (strlen($pesquisa) == 0) {
- exit;
- }
- $ligacao = mysql_connect('localhost', 'root', 'flag');
- if (!$ligacao) {
- die('Não foi possível conetar ao MySQL: ' . mysql_error() . "<br/>");
- }
- $ligacao_bd = mysql_select_db('sex_shop');
- if (!$ligacao_bd) {
- die('Não consegui seleccionar a BD sex_shop: ' . mysql_error() . "<br/>");
- }
- mysql_set_charset('utf8');
- $resultado = mysql_query(
- "select * from PRODUTOS where upper(NOME) like upper('%" . $pesquisa . "%') or upper(DESCRICAO) like
- upper('%" . $pesquisa . "%') order by DESCRICAO");
- if (!$resultado) {
- echo "Erro na pergunta SQL " . mysql_error() . "<br/>";
- exit;
- }
- //verificar quantidade de registos obtidos
- $qtd_linhas = mysql_num_rows($resultado);
- if ($qtd_linhas > 0) {
- ?>
- <br/>
- <table border="0" cellcellpadding="0" cellspacing="0">
- <?php
- while ($linha = mysql_fetch_assoc($resultado)) {
- echo "<tr><td>" . str_ireplace($pesquisa, "<b>" . $pesquisa . "</b>", $linha["Nome"]) . "</td>";
- echo "<td>" . str_ireplace($pesquisa, "<b>" . $pesquisa . "</b>", $linha["Descricao"]) . "</td>";
- }
- ?>
- </table>
- <?php
- }
- mysql_close($ligacao);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement