Pessoal, preciso de uma ajuda meio urgente. tenho um script em php onde eu pagino os resultados e tenho dois tipos de resultados ( paga mensal / nao paga ). Preciso que os clientes cadastrados no banco de dados com o SELECT Paga_mensal = 'sim' apareca antes dos que nao pagam alguem pode me ajudar por favor. abaixo segue o script da pagina de consulta e resultados.
[codebox]<?
//--------------->>> incio do metodo de busca
// busca empresas por letra ( x )
if($_GET['indice']){
$itemLetra = $_GET['indice'];
$sql_indice = SelecionaRegistro("WHERE empresa LIKE '$itemLetra%' ORDER BY paga_mensal DESC, empresa ASC", 'tb_empresas') or print mysql_error();
}
// total de itens a serem exibidas
$np = 12;
// total de colunas
$colunas = 1;
// verifica se esta na pagina 1
if($_GET['pg']){
$pg = $_GET['pg'];
} else {
$pg = 1;
}
// valores iniciais
$inicio = $pg - 1;
$inicio = $inicio * $np;
// dados para paginacao
$limite = SelecionaRegistro("WHERE empresa LIKE '$itemLetra%' ORDER BY paga_mensal DESC, empresa ASC LIMIT $inicio, $np", 'tb_empresas');
$tr = mysql_num_rows($sql_indice);
$tp = $tr / $np;
$tp = ceil($tp);
?>
<link href="../lib.css/novo.css" rel="stylesheet" type="text/css" />
<table width="100%" border="0" cellspacing="2" cellpadding="0">
<?
// exibe regsitros
// while($rowBusca=mysql_fetch_array($limite)){
?>
<tr>
<td><table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td><table width="520" border="0" cellpadding="0" cellspacing="3" class="PesquisaHome">
<tr>
<td width="28" bgcolor="#F9EE7B"><div align="center"></div></td>
<td width="167" bgcolor="#F9EE7B"><div align="center" class="ItensMenuLAteral">Empresa</div></td>
<td width="125" bgcolor="#F9EE7B"><div align="center">Segmento</div></td>
<td width="108" bgcolor="#F9EE7B"><div align="center">Endereço</div></td>
<td width="80" bgcolor="#F9EE7B"><div align="center">Telefone</div></td>
</tr>
</table></td>
</tr>
<?
$cont = 0;
while($rowPesquisa=mysql_fetch_array($limite)){
if($cont%2==0) $cor = "F1F3F5"; else $cor = "FCF7BF";
$cont++;
// verifica se a empresa tem ou nao foto cadastrada
$sql_foto = SelecionaRegistro("where id_empresa = '".$rowPesquisa['id']."' order by id desc", 'tb_empresasfotos');
$numero_de_fotos = mysql_num_rows($sql_foto);
if($numero_de_fotos>=1){
$imagem = "<img src='/pontashop/lib.imgs/camera_sim.gif'>";
} else {
$imagem = "";
}
// MOSTRAR LINK PARA PAGINA DETALHES SOMENTE DOS CLIENTES QUE PAGAM MENSAL
if($rowPesquisa['paga_mensal']=='Sim'){
$LinkPagante = "java script:Detalhes($rowPesquisa[id])";
} else {
$LinkPagante = "#";
}
?>
<tr>
<td width="5%"><table width="520" border="0" cellpadding="0" cellspacing="3" class="PesquisaHome">
<tr bgcolor="<?=$cor;?>">
<td width="28"><? echo $imagem; ?></td>
<td width="167"><table width="150" border="0" cellpadding="0" cellspacing="0" class="TituloItemMenuLateral">
<tr>
<td width="100%"><div align="justify"><a href="<?=$LinkPagante;?>"><? echo $rowPesquisa['empresa']; ?></a></div></td>
</tr>
</table></td>
<td width="123"><table width="123" border="0" cellpadding="0" cellspacing="0" class="TituloItemMenuLateral">
<tr>
<td><a href="<?=$LinkPagante;?>"><? echo BUSCACATEGORIA($rowPesquisa['id_categoria']); ?></a></td>
</tr>
</table>
<a href="<?=$LinkPagante;?>"></a></td>
<td width="106"><table width="106" border="0" cellpadding="0" cellspacing="0" class="TituloItemMenuLateral">
<tr>
<td><a href="<?=$LinkPagante;?>"><? echo $rowPesquisa['endereco']; ?> <? echo $rowPesquisa['numero']; ?></a></td>
</tr>
</table></td>
<td width="82"><table width="82" border="0" cellpadding="0" cellspacing="0" class="TituloItemMenuLateral">
<tr>
<td><a href="<?=$LinkPagante;?>">
<? $a = eregi_replace("-", ".", $rowPesquisa['fone']); $b = @eregi_replace(" ", "", $a); echo $b;?>
<? $a = eregi_replace("-", ".", $rowPesquisa['fax']); $b = @eregi_replace(" ", "", $a); echo $b;?>
</a></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<? } ?>
</table></td>
</tr>
</table>
<table width="95%" height="30" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td width="62%" bgcolor="f3f8be" class="ItensMenuLateral"><div align="center" class="ItensMenuLAteral">Exibindo: <? echo mysql_num_rows($limite); ?> - Total de Registros: <? echo $tr; ?> - Total de Páginas: <? echo $tp; ?></div></td>
<td width="38%" bgcolor="f3f8be" class="ItensMenuLateral"><div align="center">
<?
$proximo = $pg + 1;
$anterior = $pg - 1;
if ($pg>=1) {
if($pg>1){
echo " <a href='?php=all&indice=$indice&id=all&item=all&pg=$anterior'><- Anterior</a> ";
} else {
echo " <- Anterior ";
}
}
echo "|";
if ($pg<=$tp) {
if($pg<$tp){
echo " <a href='?php=all&indice=$indice&id=all&item=all&pg=$proximo'>Próxima -></a> ";
} else {
echo " Próxima -> ";
}
}
?>
<br />
</div></td>
</tr>
<tr>
<td colspan="2" bgcolor="f3f8be" class="ItensMenuLateral"><div align="center">
<?
for($i=1; $i<=$tp; $i++){
if($i==$pg){
echo " (<b>$i</b>) ";
} else {
echo " (<a href='?php=all&indice=$indice&id=all&item=all&pg=$i'>$i</a>) ";
}
}
?>
</div></td>
</tr>
</table>
[/codebox]

Ordenar Resultado Por Status
Started By epcosta, 17/09/2007, 16:14
1 reply to this topic
#1
Posted 17/09/2007, 16:14
#2
Posted 17/09/2007, 16:45
Bom, se eu entendi direito o seu script está mostrando os registros onde paga_mensal é igual a sim antes dos não, ou estão mostrando os registros em ordem de entrada.
Se for alguma destas alternativas apenas troque o
Falopa!
Se for alguma destas alternativas apenas troque o
ORDER BY paga_mensal DESCpor
ORDER BY paga_mensal ASC
Falopa!
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)