Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Problemas com switch em menu


Guest --Neo --

Pergunta

Estou com um problema com switch em um menu q fiz esta dando o seguinte erro=>

Warning: Failed opening '/veiculos.php?id_categoria=1' for inclusion (include_path='.;c:\apache\php\pear') in c:\apache\htdocs\onovo\index.php on line 37

Estou fazendo assim o menu

E onde o link assim

<a href="index.php?pag=carros">&raquo; Carros</a>

<?php
           switch($_GET['pag']){
               case 'carros': include "veiculos.php?id_categoria=1"; break;           
               default: include "centro.php"; break;                
           }
     ?>

Link para o comentário
Compartilhar em outros sites

16 respostass a esta questão

Posts Recomendados

  • 0

mesmo com header da o seguinte erro Warning: Cannot add header information - headers already sent by (output started at c:\apache\htdocs\onovo\index.php:7) in c:\apache\htdocs\onovo\index.php on line 37

fiz assim => case 'carros': header ("veiculos.php?id_categoria=1"); break;

Link para o comentário
Compartilhar em outros sites

  • 0

meu cod esta assim

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Neg&oacute;cios A Mais - O ponto certo para compra e venda!</title>
<link href="_css/estilo.css" rel="stylesheet" type="text/css" />
<link rel="SHORTCUT ICON" href="_img/favicon.ico" />
<script type="text/javascript" language="JavaScript">
<!--
function add_bookmark() { 
var browsName = navigator.appName; 
if (browsName == "Microsoft Internet Explorer") { 
window.external.AddFavorite('http://www.negociosamais.com.br','Negócios A+ - O ponto certo para compra e venda!' );
} else if (browsName == "Netscape") { 
alert ("Para adicionar nosso site ao seu BookMark aperte CTRL+D"); 
}
}
// -->
</script>
</head>
<body>
<table height="43%" width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="192" align="center" valign="top"><table width="770" border="0" cellpadding="0" cellspacing="0" background="_img/bg_topo.jpg" bgcolor="#F45201" style="background-repeat:repeat-x">
      <?php include("topo.php"); ?>
    </table>
    <div><img src="_img/spacer.gif" width="770" height="5" /></div>
    <table width="770" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <?php include("menu.php"); ?>
        <td width="5" height="139"><img src="_img/spacer.gif" width="5" height="100" /></td>
        <td valign="top"><!-- INÍCIO DA COLUNA MENU VEÍCULOS -->
          <table width="422" border="0" cellspacing="0" cellpadding="0">
            <tr>
            <?php
           switch($_GET['pag']){
               case 'carros': header ("veiculos.php?id_categoria=1"); break;    
               case 'motos': include "veiculos.php?id_categoria=2"; break;    
               case 'caminhoes': include "veiculos.php?id_categoria=3"; break;
               case 'apartamentos': include "imoveis.php?id_categoria=4"; break;
               case 'casas': include "imoveis.php?id_categoria=5"; break;       
               case 'chacaras': include "imoveis.php?id_categoria=6"; break;    
               case 'lotes': include "imoveis.php?id_categoria=7"; break;       
               case 'salas': include "imoveis.php"; break;       
               case 'computadores': include "informatica.php?id_categoria=9"; break; 
               case 'notebooks': include "informatica.php?id_categoria=10"; break;   
               case 'cameras': include "informatica.php?id_categoria=11"; break;     
               case 'mp3': include "informatica.php?id_categoria=12"; break;        
               case 'pecas': include "informatica.php?id_categoria=13"; break;      
               case 'acessorios': include "informatica.php?id_categoria=14"; break; 
               case 'empresa': include "empresa.php"; break;        
               case 'anuncie': include "anunciar.php"; break;        
               case 'painel': include "login.php"; break;        
               case 'regras': include "regras.php"; break;        
               case 'faq': include "faq.php"; break;        
               case 'contato': include "contato.php"; break;        
               default: include "centro.php"; break;                
           }
     ?>
            <tr>
              <td height="120"></td>
            </tr>
          </table></td>
        <td width="5"><img src="_img/spacer.gif" width="5" height="100" /></td>
        <?php include("menu_lateral.php"); ?>
      </tr>
    </table>
    <table width="770" height="35" border="0" cellspacing="0" cellpadding="0" background="_img/bg_copyright.png" style="background-repeat:no-repeat; background-position:center" class="copyright">
     <?php include("baixo.php"); ?>
    </table>
    <div><img src="_img/spacer.gif" width="770" height="7" /></div></td>
  </tr>
</table>

<map name="Map" id="Map"><area shape="rect" coords="0,0,13,11" href="#" alt="Página Inicial" />
<area shape="rect" coords="21,0,34,10" href="java script:add_bookmark();" target="_self" alt="Nos adicione em seus favoritos!" />
<area shape="rect" coords="43,0,56,10" href="#" alt="Entre em contato conosco" />
</map></body>
</html>

Link para o comentário
Compartilhar em outros sites

  • 0

Mas como passar a variavel = id_categoria=1 no select na pagina veiculos para retornar somente carros q o ID deles na tabelas categoria e o valor "1"

$info = $id_categoria;

$sql_usados = "select * from anuncios where id_categoria='$info'";

Link para o comentário
Compartilhar em outros sites

  • 0

fiz da forma q você me falou mas ainda não passou o valor segue as tres paginas q estou usando

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Neg&oacute;cios A Mais - O ponto certo para compra e venda!</title>
<link href="_css/estilo.css" rel="stylesheet" type="text/css" />
<link rel="SHORTCUT ICON" href="_img/favicon.ico" />
<script type="text/javascript" language="JavaScript">
<!--
function add_bookmark() { 
var browsName = navigator.appName; 
if (browsName == "Microsoft Internet Explorer") { 
window.external.AddFavorite('http://www.negociosamais.com.br','Negócios A+ - O ponto certo para compra e venda!' );
} else if (browsName == "Netscape") { 
alert ("Para adicionar nosso site ao seu BookMark aperte CTRL+D"); 
}
}
// -->
</script>
</head>
<body>
<table height="43%" width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="192" align="center" valign="top"><table width="770" border="0" cellpadding="0" cellspacing="0" background="_img/bg_topo.jpg" bgcolor="#F45201" style="background-repeat:repeat-x">
      <?php include("topo.php"); ?>
    </table>
    <div><img src="_img/spacer.gif" width="770" height="5" /></div>
    <table width="770" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <?php include("menu.php"); ?>
        <td width="5" height="139"><img src="_img/spacer.gif" width="5" height="100" /></td>
        <td valign="top"><!-- INÍCIO DA COLUNA MENU VEÍCULOS -->
          <table width="422" border="0" cellspacing="0" cellpadding="0">
            <tr>
            <?php
require "case_menu.php";
?>
            <tr>
              <td height="120"></td>
            </tr>
          </table></td>
        <td width="5"><img src="_img/spacer.gif" width="5" height="100" /></td>
        <?php include("menu_lateral.php"); ?>
      </tr>
    </table>
    <table width="770" height="35" border="0" cellspacing="0" cellpadding="0" background="_img/bg_copyright.png" style="background-repeat:no-repeat; background-position:center" class="copyright">
     <?php include("baixo.php"); ?>
    </table>
    <div><img src="_img/spacer.gif" width="770" height="7" /></div></td>
  </tr>
</table>

<map name="Map" id="Map"><area shape="rect" coords="0,0,13,11" href="#" alt="Página Inicial" />
<area shape="rect" coords="21,0,34,10" href="java script:add_bookmark();" target="_self" alt="Nos adicione em seus favoritos!" />
<area shape="rect" coords="43,0,56,10" href="#" alt="Entre em contato conosco" />
</map></body>
</html>
case_menu.php
<?php
           switch($_GET['pag']){
               case 'carros': header "veiculos.php?pag=1"; break;    
               case 'motos': include "veiculos.php"; break;    
               case 'caminhoes': include "veiculos.php?id_categoria=3"; break;
               case 'apartamentos': include "imoveis.php?id_categoria=4"; break;
               case 'casas': include "imoveis.php?id_categoria=5"; break;       
               case 'chacaras': include "imoveis.php?id_categoria=6"; break;    
               case 'lotes': include "imoveis.php?id_categoria=7"; break;       
               case 'salas': include "imoveis.php"; break;       
               case 'computadores': include "informatica.php?id_categoria=9"; break; 
               case 'notebooks': include "informatica.php?id_categoria=10"; break;   
               case 'cameras': include "informatica.php?id_categoria=11"; break;     
               case 'mp3': include "informatica.php?id_categoria=12"; break;        
               case 'pecas': include "informatica.php?id_categoria=13"; break;      
               case 'acessorios': include "informatica.php?id_categoria=14"; break; 
               case 'empresa': include "empresa.php"; break;        
               case 'anuncie': include "anunciar.php"; break;        
               case 'painel': include "login.php"; break;        
               case 'regras': include "regras.php"; break;        
               case 'faq': include "faq.php"; break;        
               case 'contato': include "contato.php"; break;        
               default: include "centro.php"; break;                
           }
     ?>
veiculos.php
<?
 @include ("abrebanco.php");
 @include ("config.php");
?>

<?
$result_pag = 10;

 if($pagina==""){
   $pag_atual = 1;
 }else{
   $pag_atual = $pagina;
 }

$info = $pag;

$sql_usados = "select * from anuncios where id_categoria='$info'";
$carros = mysql_query($sql_usados);
$pagesize = $result_pag;
$cachesize = $result_pag;
$carros = mysql_query($sql_usados);

$total = mysql_num_rows($carros);
$pagecount = $total/$result_pag;

$conta_pag = round($pagecount);

if($pag_atual > $conta_pag){
$pag_atual = $conta_pag;
}

?>

<td valign="top"><!-- INÍCIO DA COLUNA MENU VEÍCULOS -->
          <table width="422" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><img src="_img/title_destaques.png" alt="Produtos em Destaque" width="422" height="56" /></td>
            </tr>
            <tr>
              <td align="center" bgcolor="#FFE3B8">
              <?
if($pag_atual< 1){
$pag_atual = 1;
}
if($total == "0"){
  echo "<center>Nenhum resultado encontrado!</center>";
}else{
  $absolutepage = $pag_atual;
}
      ?>
      <table width="409" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="100"> 
                  <?=$fonte01?>
                  página 
                  <?=$pag_atual?>
                  de 
                  <?=$conta_pag?>
                </td>
                <td width="309" align="right"><?=$fonte01?>
                <?
                // anterior
                if($pag_atual>1){
                ?>
                <a href="carros_usados.php?pagina=<?=$pag_atual - 1?>">[&lt;&lt;]</a>
                <?
                }
                
                // numeros
                for ($I = 1; $I <=$conta_pag; $I ++) {
                if ($I == $pag_atual) {
                echo $I;
                }else{
                ?>
                <a href="carros_usados.php?pagina=<?=$I?>"><?=$I?></a>
                <?
                }
                }
                
                // proximo
                if($pag_atual<$conta_pag){
                ?>
                <a href="carros_usados.php?pagina=<?=$pag_atual + 1?>">[&gt;&gt;]</a>
                <?
                }
                ?>
                </td>
              </tr>
            </table>
      <br>
      <table width="410" border="0" cellspacing="0" cellpadding="0">
        <tr bgcolor="#0066CC"> 
          <td width="95" align="center"> 
            <?=$fonte03?>
            Marca</font></td>
          <td width="97" align="center"> 
            <?=$fonte03?>
            Modelo</font></td>
          <td width="88" align="center"> 
            <?=$fonte03?>
            Pre&ccedil;o</font></td>
          <td width="64" align="center"> 
            <?=$fonte03?>
            Foto</font></td>
          <td width="66" align="center"> 
            <?=$fonte03?>
            &nbsp;</font></td>
        </tr>
<?
            $result_exibidos = 0; 
  while($row = mysql_fetch_array($carros,MYSQL_ASSOC)){
    if ($td_cor=="1"){
      $td="<td align=center bgcolor=#DBDBDB";
$td_mais = "<td align='center' bgcolor='#DBDBDB' width='50'>";
      $td_cor="0";
    }else{
      $td="<td align=center bgcolor=#EDEDED";
$td_mais = "<td align='center' bgcolor='#EDEDED' width='50'>";
      $td_cor="1";
    } 
            $sql_marca = "select * from marcas where id='$row[marca]'";
            $marca =mysql_query($sql_marca);

            $sql_modelo = "select * from modelos where id='$row[modelo]'";
            $modelo = mysql_query($sql_modelo);
            
          echo "<tr height='20'>";
          echo $td .">". $fonte01 . mysql_result($marca,0,"marca") . "</font></td>";
          echo $td .">". $fonte01 . mysql_result($modelo,0,"modelo") . "</font></td>";
          echo $td .">". $fonte01 .$row[preço]. "</font></td>";
          if ($row[foto]!=""){
          echo $td . "> <img src='_img/icon_foto_sim.gif'></td>";
          }else{
          echo $td . "> <img src='_img/icon_foto_nao.gif'></td>";
          }
          echo $td_mais . $fonte01 . "<a href='mais.php?numero=".$row[id_anuncio]."' class=cordolink>mais info</a></font></td>";
          echo "</tr>";
          $result_exibidos = result_exibidos + 1;
          }
        ?>
      </table>
      <br>
      <table width="413" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="100"> 
                  <?=$fonte01?>
                  página 
                  <?=$pag_atual?>
                  de 
                  <?=$conta_pag?>
                </td>
                <td width="313" align="right"><?=$fonte01?>
                <?
                // anterior
                if($pag_atual>1){
                ?>
                <a href="carros_usados.php?pagina=<?=$pag_atual - 1?>">[&lt;&lt;]</a>
                <?
                }
                
                // numeros
                for ($I = 1; $I <=$conta_pag; $I ++) {
                if ($I == $pag_atual) {
                echo $I;
                }else{
                ?>
                <a href="carros_usados.php?pagina=<?=$I?>"><?=$I?></a>
                <?
                }
                }
                
                // proximo
                if($pag_atual<$conta_pag){
                ?>
                <a href="carros_usados.php?pagina=<?=$pag_atual + 1?>">[&gt;&gt;]</a>
                <?
                }
                ?>
                </td>
              </tr>
            </table></td>
            </tr>
            <tr>
              <td valign="top"><img src="_img/curve_destaques.gif" width="422" height="7" /></td>
            </tr>
          </table>
          <div><img src="_img/spacer.gif" width="100" height="5" /></div>
                <div><img src="_img/spacer.gif" width="100" height="5" /></div>
          <table width="422" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><img src="_img/upload/banner_empresa.gif" alt="Saiba mais sobre a Negócios A+" width="208" height="57" /></td>
              <td width="5"><img src="_img/spacer.gif" width="5" height="40" /></td>
              <td><img src="_img/upload/banner_produto.gif" alt="Produto anunciado é produto vendido!" width="208" height="57" /></td>
            </tr>
          </table>
          <div><img src="_img/spacer.gif" width="100" height="7" /></div>
          <table width="422" border="0" cellspacing="0" cellpadding="0" class="pub_bottom">
            <tr>
              <td height="8" style="border:none" align="left"><img src="_img/n_publicidade_2.gif" alt="Publicidade" width="64" height="8" /></td>
            </tr>
            <tr>
              <td height="120">&nbsp;</td>
            </tr>
          </table></td>

Link para o comentário
Compartilhar em outros sites

  • 0

+/- não entendi muita coisa, la foi so um exemplo de como esta ...o que esta mesmo e so , mas não posso fazer isso então ?pag=1";break;

<?php

switch($_GET['pag']){

case 'carros': header "veiculos.php?pag=1"; break;

}

?>

Link para o comentário
Compartilhar em outros sites

  • 0

Com header() você pode. É como se você acessasse uma página normalmente, mas adicionando variáveis na URL.

O que não pode é haver query string na inclusão de arquivos. Afinal, não há lógica ao tentar incluir o arquivo x.php?id=4; isso é um arquivo inválido. Mas faria sentido incluir o arquivo x.php. ;)

Link para o comentário
Compartilhar em outros sites

  • 0

ta ate ai entendi, que no include e no requeri não posso colocar o pag.php?id=1

mas no header posso fazer mas não esta passando o valor também.

mesmo fazendo assim =>

<?php

switch($_GET['pag']){

case 'carros': header "veiculos.php?pag=1"; break;

}

?>

não esta dando certo não manda para a outra pagina veiculos.php o valor "1"

Link para o comentário
Compartilhar em outros sites

  • 0

Desta forma também da erro => Warning: Cannot add header information - headers already sent by (output started at c:\apache\htdocs\onovo\index.php:7) in c:\apache\htdocs\onovo\index.php on line 46

Mas muito obrigado Beraldo, vo deu uma luz ai fui olhando ate achar uma forma e voala..

Fiz da seguinte forma e deu certo

No menu.php

Coloquei assim

<a href="index.php?pag=carros&id_categoria=1">&raquo; Carros</a>

Depois no index.php

<?php

switch($_GET['pag']){

case 'carros': include "veiculos.php"; break;

}

?>

E finalmente a pag de veiculos.php recebe os dados

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652,1k
×
×
  • Criar Novo...