Jump to content
Fórum Script Brasil
  • 0

Linkar Pela Variavel


Guest Gustavo Rodrigues Marques
 Share

Question

Guest Gustavo Rodrigues Marques

estou com um problema, e gostaria de ajuda

preciso linkar no meu menu pela variavel que vai ser exibida na tabela

a tabela q tenho é a mesma para todos as paginas

e na hora de inserir mudaria apena um <select>

assim eu queria linkar por essa select... se ela fosse inserida no modo (MOTO), la no link Moto abrisse só as motos

ou se fosse inserido (CARRO), la no link carro quando eu clicasse aparecesse só os carros inseridos

me falaram q no link do menu devo colocar assim:

<a href=link.php?tipo=carro>..</a>

<a href=link.php?tipo=moto>,,</a>

e na tabela colocar um php

<?php mysql_query("select * from veiculos where tipo=$tipo"); ?>

mas não deu certo

sou novato em programaçao

por favor ajudem

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
Guest Gustavo Rodrigues Marques
Coloque:

<?php
$tipo = $_GET['tipo'];
$sql = mysql_query("select * from veiculos where tipo='$tipo'"); 
?>

coloquei isso e mesmo assim ele não puxou =///

Link to comment
Share on other sites

  • 0
Guest Gustavo Rodrigues Marques

bom vo coloca aqui entaum meu codigo

(obs: o nome da tabela no banco é carros mesmo)

a tabela carros_v.php:

(não é porque você colocou 'tipo' la que eu n tenha modificado como 'tipodeveiculo' aqui na tabela

<table width="100%"  border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="4%"><img src="imagens/noticias.jpg" width="27" height="27"></td>
        <td width="96%" bgcolor="#FECD0E"><span class="style1">CLASSIFICADOS > VEÍCULOS</span></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr> </tr>
            <tr>
              <td>
                <? if(mysql_num_rows(mysql_query("select * from carros order by codigo desc")) > 0){ ?>
                <table width="100%" border="0" cellspacing="3" cellpadding="0">
                  <tr> </tr>
                  <tr> </tr>
                  <tr>
                    <td>
                <?php
                
                $i=$i + 0;

                $max=3;

                $total = mysql_num_rows(mysql_query("select * from carros"));

                $pagina = ceil($total/$max);

                $in = $i * $max;

                $btodas = mysql_query("select * from carros order by codigo desc limit $in,$max");

                while($todas=mysql_fetch_array($btodas)){ 
                
                $tipodeveiculo = $_GET['tipodeveiculo'];
                $sql = mysql_query("select * from carros where tipodeveiculo='$tipodeveiculo'");

                ?>
                      <table width="100%" border="0" cellspacing="2" cellpadding="0">
                        <tr>
                          <td class="titulo"><table width="100%" border="0" cellpadding="0" cellspacing="3" bgcolor="#eeeeee" class="bordaa">
                              <tr>
                                <td width="100%" bgcolor="#ffffff">
                                  <div align="center" class="titulo">
                                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="3" >
                                      <tr>
                                        <td width="9%" rowspan="5">
                                          <?
                                    if(is_file($todas['foto01'])){ ?>
                                          <a href="index.php?pag=carros&id=<? echo $todas['codigo']; ?>"><img src="foto.php?tam=120&foto=<? echo $todas['foto01']; ?>" border="0"></a>
                                          <? } else { ?>
                                          <img src="foto.php?tam=125&foto=não.jpg" border="0">                                          <? } ?>                                        </td>
                                        <td width="91%"><span class="texto12pto"><a href="index.php?pag=carros&id=<? echo $todas['codigo']; ?>"><? echo $todas['nome']; ?></a></span><a href="index.php?pag=carros&id=<? echo $todas['codigo']; ?>"></a> - <span class="texto12pto"><? echo $todas['ano']; ?></span></td>
                                      </tr>
                                      <tr>
                                        <td><span class="texto12pto"><? echo $todas['cidade']; ?></span></td>
                                      </tr>
                                      <tr>
                                        <td><span class="texto12pto"><? echo $todas['tipodeveiculo']; ?></span></td>
                                      </tr>
                                      <tr>
                                        <td class="texto12pto"><strong><a href="index.php?pag=carros&id=<? echo $todas['codigo']; ?>" class="style2">Mais detalhes</a></strong></td>
                                      </tr>
                                      <tr>
                                        <td> </td>
                                      </tr>
                                    </table>
                                </div></td>
                              </tr>
                          </table></td>
                        </tr>
                      </table>
                      <? } ?></td>
                  </tr>
                  <tr>
                    <td align="center" class="texto12pto"><div align="center"><a href="java script:history.back(1);">Voltar</a></div></td>
                  </tr>
                  <tr>
                    <td><form name="form1" method="post" action="">
                        <div align="center"><span class="texto10pto"><strong> <br>

                      Página: </strong></span>
                            <select name="menu1" class="formulario" onChange="MM_jumpMenu('parent',this,0)">

                                      <? for($p=0;$p<$pagina;){ ?>

                                      <option <? if($p==$i){ echo "selected"; } ?> value="<? echo "".$_SERVER['PHP_SELF']."?pag=carros_v&i=$p"; ?>"><? echo "".$p+1 ."/$pagina" ?></option>

                                      <? $p++; }?>

                      </select>
                        </div>
                    </form></td>
                  </tr>
                </table>
                <? } else echo "<br><br><div align=center>Nenhum veiculo cadastrado.</div>"; ?>
              </td>
            </tr>
        </table></td>
      </tr>
      <tr> </tr>
      <tr>
        <td> </td>
      </tr>
    </table></td>
  </tr>
</table>
meu conecta.php
<?php
  $host="localhost";
  $user="root";
  $pass="";
  $dbname="jornalve_facil";
  $conecta=mysql_connect($host,$user,$pass);
  $banco=mysql_select_db($dbname) or die("Erro na conexão!");
?>
e este é um trexo do meu Menu
<table width="160" height="30" border="0" cellpadding="0" cellspacing="0">
... 
    <tr class="listViewThS1">
                  <td height="20" class="listViewThS1"> Veículos</td>
                </tr>
                <tr class="listViewPaginationTdS1">
                  <td height="20" class="listViewPaginationTdS1">- <a ref="carros_v.php?tipodeveiculo=carro">Carros</a> </td>
                </tr>
                <tr>
                  <td height="20" class="listViewPaginationTdS1">- <a href="carros_v.php?tipodeveiculo=moto">Motos</a> </td>
                </tr>
                <tr>
                  <td height="20" class="listViewPaginationTdS1">- <a href="#">Pesados</a> </td>
                </tr>
...
</table>

=//

Link to comment
Share on other sites

  • 0

A sua lógica está errada... você tá fazendo uma query para buscar os dados e dentro está colocando outra query...

$btodas = mysql_query("select * from carros order by codigo desc limit $in,$max");

                while($todas=mysql_fetch_array($btodas)){
                
                $tipodeveiculo = $_GET['tipodeveiculo'];
                $sql = mysql_query("select * from carros where tipodeveiculo='$tipodeveiculo'");
O certo seria algo do tipo...
$tipodeveiculo = $_GET['tipodeveiculo'];
$btodas = mysql_query("select * from carros where tipodeveiculo='$tipodeveiculo' order by codigo desc limit $in,$max");
while($todas=mysql_fetch_array($btodas)){

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...