Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2013 16:35
Show Gist options
  • Save anonymous/7875406 to your computer and use it in GitHub Desktop.
Save anonymous/7875406 to your computer and use it in GitHub Desktop.
<?php
require('../../dts/dbaSis.php');
require('../../dts/getSis.php');
require('../../dts/setSis.php');
require('../../dts/outSis.php');
$acao = ($_POST['acao'] ? $_POST['acao'] : $_GET['acao']);
$acao = mysql_real_escape_string($acao);
switch($acao){
case 'completar':
$search = mysql_real_escape_string($_GET['term']);
$qr = "SELECT * FROM produtos WHERE status = '1' AND titulo LIKE '%$search%' ORDER BY titulo ASC";
$ex = mysql_query($qr) or die(mysql_error());
$resJson = '[';
$first = true;
while($res = mysql_fetch_assoc($ex)):
if(!$first):
$resJson .= ', ';
else:
$first = false;
endif;
$resJson .= ucfirst(json_encode($res['titulo']));
endwhile;
$resJson .= ']';
echo $resJson;
break;
case 'pesquisar':
$pesquisa = mysql_real_escape_string($_GET['valor']);
$qr = "SELECT * FROM produtos WHERE status = '1' AND titulo LIKE '%$pesquisa%' ORDER BY titulo ASC";
$ex = mysql_query($qr) or die(mysql_error());
if(mysql_num_rows($ex) >= 1){
while($res = mysql_fetch_assoc($ex)):
echo '
<input type="text" class="quantidade" name="quantidade" class="qtd" value="1" />
<input type="text" class="valor" name="valor" class="valor" value="'.$res['valor'].'" />
<p class="p_estoque">Quantidade em estoque: '.$res['estoque'].'</p>
';
endwhile;
}else{
echo '&nbsp; Nada encontrado.';
}
break;
default:
echo 'Selecione uma ação';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment