Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Galera é o seguinte... fiz tudo direito... achando que tava dando tudo certo... e estava.... eu to montando um site de carro... então o usuário escolhe a fabricante (marca)... até ai tudo bem fiz isso, para pesquisar no db:
index.php -> link -> carros_marcas.php?marca=Audi
e o código carros_marcas.php ficou assim:
CODE
<?php
require ('cp/conexao.php');
if (!empty($_GET['marca'])) { // SE o código "marca" NÃO estiver vazio...
$seleciona = mysql_query("SELECT * FROM tb_carros WHERE marca = '" . $_GET["marca"] . "'") or die (mysql_error()); /*procura a marca no banco de dados*/
if (mysql_num_rows($seleciona) == 0) { // se nenhum registro for localizado, exibe a mensagem
die ("<h3>Desculpe, não há nenhum carro cadastrado na marca " . $_GET["marca"] . " !</h1><h4>Entre em contato com um Administrador para que<br />o problema possa ser resolvido.<br /><br />A equipe lagosMotors agradece a compreensão.");
}
else { //se for encontrado gera o resultado
while ($dados = mysql_fetch_array($seleciona)) {
// jogandos os dados nas variaveis
$id_carro = $dados["id_carro"];
$marca = $dados["marca"];
$modelo = $dados["modelo"];
$cor = $dados["cor"];
$ano = $dados["ano"];
$combustivel = $dados["combustivel"];
$portas = $dados["portas"];
$placa = $dados["placa"];
$preco = $dados["preco"];
$outros = $dados["outros"];
}
}
}
?>
<div style="border:none; position:absolute; width:717px; height:541px; left: 17px; top: 28px;">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#000000" class="style2">
<td width="15%"></td>
<td width="22%">Modelo</td>
<td width="5%">Ano</td>
<td width="21%">Combustivel</td>
<td width="6%">Portas</td>
<td width="11%">Preco</td>
<td width="20%">Acessórios</td>
</tr>
<? echo "
<tr bgcolor='#ffffff' onMouseOver=\"this.bgColor='#cccccc';\" onMouseOut=\"this.bgColor='#ffffff';\" class=\"style3\">
<td align=\"center\" valign=\"middle\"><img src=\"images/foto_lista.jpg\" width=\"80\" height=\"60\"></td>
<td> $modelo</td>
<td> $ano</td>
<td> $combustivel</td>
<td> $portas</td>
<td> R$$preco</td>
<td> $outros</td>
</tr>\n";
?>
</table></div>
Pois então, funcionar o código funciona.... mais só ta me retornando último registro adicionado, o resto não aparece... onde ta errado ai?... eu quero que ele pesquise nesse mesmo estilo, mais que retorne todos os valores do campo "marca" = " audi ".... ai gera uma lista e talz....
Desde já agradeço a atenção, Valeu!
A cara valeu mesmo! Intendi a lógica da coisa! o else tem que ficar aberto.. ai monta a primeira linha da tabela, abre o php de novo, pega o resultado que veio do db e joga para as próximas linhas e fecha o php! http://forum.imasters.com.br/public/style_emoticons/default/thumbsup.gif eu tava fazendo tudo junto ai só dava echo na primeira linha! http://forum.imasters.com.br/public/style_emoticons/default/grin.gif Valeu mesmo galera, nunca mais erro isso! http://forum.imasters.com.br/public/style_emoticons/default/clap.gif
Agradecidérrimoo..... XD
Até o próximo "desafio"!
Pois então galera tava bom de mais pra ser verdade né...
Ta tudo funcionando perfeita mente.... porém.... quando o resultado das marcas é negativo (não existe), que ele retorna com a mensagem de erro, essa mensagem ta "quebrando" o layout... olha o que acontece....
Isso aqui é resultado positivo, normal:
/applications/core/interface/imageproxy/imageproxy.php?img=http://i293.photobucket.com/albums/mm61/vidalouka/lagos_audi.jpg&key=2ffe196b55ca3ea3f6f53f00ea850a9f9503cdcbd2b1a70d42703775b282bd1a" alt="Imagem Postada" />
Isso é o resultado negativo, quebrando o layout:
/applications/core/interface/imageproxy/imageproxy.php?img=http://i293.photobucket.com/albums/mm61/vidalouka/lagos_semmarca.jpg&key=e561aebee59da7376179335e7108aca10508ef40b8dca44d12bf93133bd951d2" alt="Imagem Postada" />
A página ta assim:
CODE
<html><head>
<title>. . . : : LagosMotors.com.br : : . . .</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">td img {display: block;}body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style1 {
font-family: "BankGothic Lt BT", "BankGothic Md BT";
font-weight: bold;
font-size: 16px;
text-align:left;
}
.style2 {
color: #ffffff;
text-align:center;
}
.style3 {
text-align:center;
font-size:14px;
}
.bordatab {
border: #000000;
}
.table {
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: none;
border-right-style: none;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #000000;
border-right-color: #000000;
border-bottom-color: #000000;
border-left-color: #000000;
}
.table TD{
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: none;
border-left-style: none;
border-top-color: #000000;
border-right-color: #000000;
border-bottom-color: #000000;
border-left-color: #000000;
}
.menu {
font-family: "BankGothic Lt BT", "BankGothic Md BT";
font-weight: bold;
font-size: 14px;
text-align:left;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #000000;
}
a:hover {
text-decoration: none;
color: #000000;
}
a:active {
text-decoration: none;
color: #000000;
}
</style>
</head>
<body bgcolor="#ffffff"> <!--onLoad="document.getElementById('load').style.visibility='hidden';"-->
<!--<div id="load" style="background-color:#FFFFFF; visibility:visible; top:0px; left:0px; text-align:left; position:absolute; width:1000px; height:800px; border:none;"><h2>carregando</h2></div>-->
<script LANGUAGE="JavaScript">
function Banners()
{
var MNews = new Array();
MNews[0]= '<IMG SRC="images/carro1.jpg">'
MNews[1]= '<IMG SRC="images/carro2.jpg">'
MNews[2]= '<IMG SRC="images/carro3.jpg">'
MNews[3]= '<IMG SRC="images/carro4.jpg">'
MNews[4]= '<IMG SRC="images/carro5.jpg">'
var Numero = Math.floor(Math.random()*5);
document.write(MNews[Numero]);
}
</script>
<table border="0" cellpadding="0" cellspacing="0" width="1000">
<tr>
<td><img src="images/spacer.gif" width="9" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="185" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="31" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="125" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="8" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="470" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="16" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="142" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="14" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
<tr>
<td rowspan="7" colspan="4" width="350" height="205"><script LANGUAGE="JavaScript">
Veja_Banner = Banners();
</script><!--<img name="carro" src="images/carro.jpg" width="350" height="205" border="0" id="carro" alt="" />--></td>
<td colspan="5"><img name="index_r1_c5" src="images/index_r1_c5.jpg" width="650" height="16" border="0" id="index_r1_c5" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="16" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="3"><img name="index_r2_c5" src="images/index_r2_c5.jpg" width="494" height="62" border="0" id="index_r2_c5" alt="" /></td>
<td rowspan="4" background="images/quadrado.jpg" width="142" height="158"></td>
<td rowspan="7"><img name="index_r2_c9" src="images/index_r2_c9.jpg" width="14" height="194" border="0" id="index_r2_c9" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="62" border="0" alt="" /></td>
</tr>
<tr>
<td rowspan="6"><img name="index_r3_c5" src="images/index_r3_c5.jpg" width="8" height="132" border="0" id="index_r3_c5" alt="" /></td>
<td background="images/banner.jpg" width="470" height="62"></td>
<td rowspan="6"><img name="index_r3_c7" src="images/index_r3_c7.jpg" width="16" height="132" border="0" id="index_r3_c7" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="62" border="0" alt="" /></td>
</tr>
<tr>
<td><img name="index_r4_c6" src="images/index_r4_c6.jpg" width="470" height="18" border="0" id="index_r4_c6" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="18" border="0" alt="" /></td>
</tr>
<tr>
<td rowspan="2" background="images/barracima.jpg" width="470" height="18"></td>
<td><img src="images/spacer.gif" width="1" height="16" border="0" alt="" /></td>
</tr>
<tr>
<td rowspan="3"><img name="index_r6_c8" src="images/index_r6_c8.jpg" width="142" height="36" border="0" id="index_r6_c8" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="2" border="0" alt="" /></td>
</tr>
<tr>
<td rowspan="2"><img name="index_r7_c6" src="images/index_r7_c6.jpg" width="470" height="34" border="0" id="index_r7_c6" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="29" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="4"><img name="index_r8_c1" src="images/index_r8_c1.jpg" width="350" height="5" border="0" id="index_r8_c1" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="5" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="3"><img name="index_r9_c1" src="images/index_r9_c1.jpg" width="225" height="1" border="0" id="index_r9_c1" alt="" /></td>
<td colspan="6" rowspan="3" valign="middle"><div style="border:none; position:absolute; width:764px; height:593px; left: 230px; top: 213px;">
<table width="760" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="32" height="30" scope="row"><img src="images/caixa/c_s_e.jpg" width="32" height="30"></th>
<td width="302" background="images/caixa/c_t1.jpg"><span class="style1">Carros - <? echo $_GET['marca']; ?></span></td>
<td width="12"><img src="images/caixa/c_t2.jpg" width="12" height="30"></td>
<td width="384" background="images/caixa/c_t3.jpg"> </td>
<td width="30"><img src="images/caixa/c_s_d.jpg" width="30" height="30"></td>
</tr>
<tr>
<th height="532" background="images/caixa/l_e.jpg" scope="row"> </th>
<td colspan="3" align="left" valign="top" bgcolor="#D8D8D8"><div style="border:none; position:absolute; width:717px; height:541px; left: 17px; top: 28px;"><?php
require ('cp/conexao.php');
if (!empty($_GET['marca'])) { // SE o código "filmes" NÃO estiver vazio...
$seleciona = mysql_query("SELECT * FROM tb_carros WHERE marca = '" . $_GET["marca"] . "'") or die (mysql_error()); /*procura o código no banco de dados*/
if (mysql_num_rows($seleciona) == 0) { // se nenhum registro for localizado, exibe a mensagem
die ("<table><tr><td> Desculpe, não há nenhum carro<br />cadastrado na marca " . $_GET["marca"] . ".</td></tr></table>");
}
else {
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table">
<tr bgcolor="#000000" class="style2">
<td width="10%"></td>
<td width="22%">Modelo</td>
<td width="5%">Ano</td>
<td width="21%">Combustivel</td>
<td width="6%">Portas</td>
<td width="11%">Preco</td>
<td width="20%">Acessórios</td>
</tr>
<?
while ($dados = mysql_fetch_array($seleciona)) {
$id_carro = $dados["id_carro"];
$marca = $dados["marca"];
$modelo = $dados["modelo"];
$cor = $dados["cor"];
$ano = $dados["ano"];
$combustivel = $dados["combustivel"];
$portas = $dados["portas"];
$placa = $dados["placa"];
$preco = $dados["preco"];
$outros = $dados["outros"];
echo "
<tr bgcolor='#ffffff' onMouseOver=\"this.bgColor='#cccccc';\" onMouseOut=\"this.bgColor='#ffffff';\" class=\"style3\">
<td<img src=\"images/foto_lista.jpg\" width=\"80\" height=\"60\"></td>
<td> $modelo</td>
<td> $ano</td>
<td> $combustivel</td>
<td> $portas</td>
<td> R$$preco</td>
<td> $outros</td>
</tr>\n";
} // Termina a exibição
}}
?>
</table></div>
</td>
<td background="images/caixa/l_d.jpg"> </td>
</tr>
<tr>
<th scope="row"><img src="images/caixa/c_i_e.jpg" width="32" height="30"></th>
<td colspan="3" background="images/caixa/b.jpg"> </td>
<td><img src="images/caixa/c_i_d.jpg" width="30" height="30"></td>
</tr>
</table>
</div>
</td>
<td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
<tr>
<td rowspan="2"><img name="index_r10_c1" src="images/index_r10_c1.jpg" width="9" height="589" border="0" id="index_r10_c1" alt="" /></td>
<td valign="top" background="images/menulateral.jpg"><div style="border:none; position:absolute; width:180px; height:500px; left: 12px; top: 215px;">
<table width="174" border="0" cellpadding="0" cellspacing="0" class="menu">
<tr>
<th width="174" scope="row"><div align="center">- - MENU - -</div></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=empresa">..:: Quem Somos?</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=regras">..:: Regras do Site</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=anunciar">..:: Como Anunciar?</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=lojas">..:: Lojas</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=carros">..:: Carros</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=motos">..:: Motos</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=caminhoes">..:: Caminhões</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=ipva">..:: IPVA</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=multas">..:: Multas</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=detranrj">..:: Detran - RJ</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=estradas">..:: Estradas, etc</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=saiba">..:: Saiba Mais</a></th>
</tr>
<tr>
<th scope="row" onMouseOver="this.bgColor='#999999';" onMouseOut="this.bgColor='';"><a href="pagina.php?pag=esportelazer">..:: Esporte e Lazer</a></th>
</tr>
</table></div></td>
<td rowspan="2"><img name="index_r10_c3" src="images/index_r10_c3.jpg" width="31" height="589" border="0" id="index_r10_c3" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="575" border="0" alt="" /></td>
</tr>
<tr>
<td><img name="index_r11_c2" src="images/index_r11_c2.jpg" width="185" height="14" border="0" id="index_r11_c2" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="14" border="0" alt="" /></td>
</tr>
</table>
</body>
</html>
Como resolver isso galera? "/
if (mysql_num_rows($seleciona) == 0) { // se nenhum registro for localizado, exibe a mensagem
else { //se for encontrado gera o resultado
<?
while ($dados = mysql_fetch_array($seleciona)) {
} // Termina a exibição
}}