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

Erro ao efetuar uma busca (PHP e Mysql)


saulus

Pergunta

Bom galera to com um pequeno problema, toda vez que eu vou efetuar uma certa busca no site o resultado dessa busca não é exibido, no final da página aparece a seguinte mensagem:

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/saulolag/public_html/auto/resultado.php  on line 1101
não sei bem o que é, sera que alguém poderia me ajudar? abaixo segue os códigos do arquivo resultado.php
<?php require_once('Connections/portalveic.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php require_once('Connections/portalveic.php'); ?>
<?php require_once('Connections/portalveic.php'); ?>
<?php require_once('Connections/portalveic.php'); ?>
<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }



  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);



  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;    

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}



$currentPage = $_SERVER["PHP_SELF"];

mysql_select_db($database_portalveic, $portalveic);
$query_mascas_lista = "SELECT * FROM marcas ORDER BY marca ASC";
$mascas_lista = mysql_query($query_mascas_lista, $portalveic) or die(mysql_error());
$row_mascas_lista = mysql_fetch_assoc($mascas_lista);
$totalRows_mascas_lista = mysql_num_rows($mascas_lista);



if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }



  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);



  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;    

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}



if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }



  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);



  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;    

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}



if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }



  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);



  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;    

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}



$maxRows_empresa = 12;

$pageNum_empresa = 0;

if (isset($_GET['pageNum_empresa'])) {

  $pageNum_empresa = $_GET['pageNum_empresa'];

}

$startRow_empresa = $pageNum_empresa * $maxRows_empresa;



mysql_select_db($database_portalveic, $portalveic);

$query_empresa = "SELECT * FROM empresa";

$query_limit_empresa = sprintf("%s LIMIT %d, %d", $query_empresa, $startRow_empresa, $maxRows_empresa);

$empresa = mysql_query($query_limit_empresa, $portalveic) or die(mysql_error());

$row_empresa = mysql_fetch_assoc($empresa);



if (isset($_GET['totalRows_empresa'])) {

  $totalRows_empresa = $_GET['totalRows_empresa'];

} else {

  $all_empresa = mysql_query($query_empresa);

  $totalRows_empresa = mysql_num_rows($all_empresa);

}

$totalPages_empresa = ceil($totalRows_empresa/$maxRows_empresa)-1;



$maxRows_ultimos_cadastrados = 6;

$pageNum_ultimos_cadastrados = 0;

if (isset($_GET['pageNum_ultimos_cadastrados'])) {

  $pageNum_ultimos_cadastrados = $_GET['pageNum_ultimos_cadastrados'];

}

$startRow_ultimos_cadastrados = $pageNum_ultimos_cadastrados * $maxRows_ultimos_cadastrados;



mysql_select_db($database_portalveic, $portalveic);

$query_ultimos_cadastrados = "SELECT * FROM auto ORDER BY id DESC";

$query_limit_ultimos_cadastrados = sprintf("%s LIMIT %d, %d", $query_ultimos_cadastrados, $startRow_ultimos_cadastrados, $maxRows_ultimos_cadastrados);

$ultimos_cadastrados = mysql_query($query_limit_ultimos_cadastrados, $portalveic) or die(mysql_error());

$row_ultimos_cadastrados = mysql_fetch_assoc($ultimos_cadastrados);



if (isset($_GET['totalRows_ultimos_cadastrados'])) {

  $totalRows_ultimos_cadastrados = $_GET['totalRows_ultimos_cadastrados'];

} else {

  $all_ultimos_cadastrados = mysql_query($query_ultimos_cadastrados);

  $totalRows_ultimos_cadastrados = mysql_num_rows($all_ultimos_cadastrados);

}

$totalPages_ultimos_cadastrados = ceil($totalRows_ultimos_cadastrados/$maxRows_ultimos_cadastrados)-1;



$maxRows_destaques = 12;

$pageNum_destaques = 0;

if (isset($_GET['pageNum_destaques'])) {

  $pageNum_destaques = $_GET['pageNum_destaques'];

}

$startRow_destaques = $pageNum_destaques * $maxRows_destaques;



mysql_select_db($database_portalveic, $portalveic);

$query_destaques = "SELECT * FROM auto WHERE veiculo = 'Motos Usadas'";

$query_limit_destaques = sprintf("%s LIMIT %d, %d", $query_destaques, $startRow_destaques, $maxRows_destaques);

$destaques = mysql_query($query_limit_destaques, $portalveic) or die(mysql_error());

$row_destaques = mysql_fetch_assoc($destaques);



if (isset($_GET['totalRows_destaques'])) {

  $totalRows_destaques = $_GET['totalRows_destaques'];

} else {

  $all_destaques = mysql_query($query_destaques);

  $totalRows_destaques = mysql_num_rows($all_destaques);

}

$totalPages_destaques = ceil($totalRows_destaques/$maxRows_destaques)-1;



$maxRows_resultado_busca = 1;

$pageNum_resultado_busca = 0;

if (isset($_GET['pageNum_resultado_busca'])) {

  $pageNum_resultado_busca = $_GET['pageNum_resultado_busca'];

}

$startRow_resultado_busca = $pageNum_resultado_busca * $maxRows_resultado_busca;



$colname_resultado_busca = "-1";

if (isset($_POST['marca'])) {

  $colname_resultado_busca = $_POST['marca'];

}

mysql_select_db($database_portalveic, $portalveic);

$query_resultado_busca = sprintf("SELECT * FROM auto WHERE marca = %s", GetSQLValueString($colname_resultado_busca, "text"));

$query_limit_resultado_busca = sprintf("%s LIMIT %d, %d", $query_resultado_busca, $startRow_resultado_busca, $maxRows_resultado_busca);

$resultado_busca = mysql_query($query_limit_resultado_busca, $portalveic) or die(mysql_error());

$row_resultado_busca = mysql_fetch_assoc($resultado_busca);



if (isset($_GET['totalRows_resultado_busca'])) {

  $totalRows_resultado_busca = $_GET['totalRows_resultado_busca'];

} else {

  $all_resultado_busca = mysql_query($query_resultado_busca);

  $totalRows_resultado_busca = mysql_num_rows($all_resultado_busca);

}

$totalPages_resultado_busca = ceil($totalRows_resultado_busca/$maxRows_resultado_busca)-1;



$queryString_resultado_busca = "";

if (!empty($_SERVER['QUERY_STRING'])) {

  $params = explode("&", $_SERVER['QUERY_STRING']);

  $newParams = array();

  foreach ($params as $param) {

    if (stristr($param, "pageNum_resultado_busca") == false && 

        stristr($param, "totalRows_resultado_busca") == false) {

      array_push($newParams, $param);

    }

  }

  if (count($newParams) != 0) {

    $queryString_resultado_busca = "&" . htmlentities(implode("&", $newParams));

  }

}

$queryString_resultado_busca = sprintf("&totalRows_resultado_busca=%d%s", $totalRows_resultado_busca, $queryString_resultado_busca);

?>
<!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>.::<?php echo $row_empresa['empresa']; ?>::.</title>

<link rel="stylesheet" type="text/css" href="../style-projects-jquery.css" />  

   <script type="text/javascript" src="js/jquery.js"></script>



</style>

<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

<link href="style.css" rel="stylesheet" type="text/css" />

<style type="text/css">

<!--

.style1 {

        font-family: Verdana, Arial, Helvetica, sans-serif;

        font-size: 12px;

}

.style3 {

        font-family: Verdana, Arial, Helvetica, sans-serif;

        font-size: 10px;

        color: #999999;

}

#nome{

        width:200px;

        height:25px;

        border: 1px solid #CCC;

        background:#FFF;

        color:#CCC;

        padding-top:4px;

        font-family:Verdana, Geneva, sans-serif;

}

#email{

        width:200px;

        height:25px;

        border: 1px solid #CCC;

        background:#FFF;

        color:#CCC;

        padding-top:4px;

        font-family:Verdana, Geneva, sans-serif;

}



#telefone{

        width:200px;

        height:25px;

        border: 1px solid #CCC;

        background:#FFF;

        color:#CCC;

        padding-top:4px;

        font-family:Verdana, Geneva, sans-serif;

}



#estado{

        width:200px;

        height:25px;

        border: 1px solid #CCC;

        background:#FFF;

        color:#CCC;

        padding-top:4px;

        font-family:Verdana, Geneva, sans-serif;

}



#cidade{

        width:200px;

        height:25px;

        border: 1px solid #CCC;

        background:#FFF;

        color:#CCC;

        padding-top:4px;

        font-family:Verdana, Geneva, sans-serif;

}

#assunto{

        width:200px;

        height:25px;

        border: 1px solid #CCC;

        background:#FFF;

        color:#CCC;

        padding-top:4px;

        font-family:Verdana, Geneva, sans-serif;

}



#mensagem{

        width:200px;

        height:200px;

        border: 1px solid #CCC;

        background:#FFF;

        color:#CCC;

        padding-top:4px;

        font-family:Verdana, Geneva, sans-serif;

}

</style>

   <!-- Arquivos utilizados pelo jQuery lightBox plugin -->

    <script type="text/javascript" src="js/jquery.js"></script>

    <script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script>

    <link rel="stylesheet" type="text/css" href="css/jquery.lightbox-0.5.css" media="screen" />

    <!-- / fim dos arquivos utilizados pelo jQuery lightBox plugin -->

    

    <!-- Ativando o jQuery lightBox plugin -->

    <script type="text/javascript">

    $(function() {

        $('#gallery a').lightBox();

    });

    </script>

        <style type="text/css">

        /* jQuery lightBox plugin - Gallery style */

        #gallery {

                width: 100%;

        }

        #gallery ul { list-style: none; }

        #gallery ul li { display: inline; }

        #gallery ul img {

                border: 5px solid #3e3e3e;

                border-width: 5px 5px 20px;

        }

        #gallery ul a:hover img {

                border: 5px solid #fff;

                border-width: 5px 5px 20px;

                color: #fff;

        }

        #gallery ul a:hover { color: #fff; }

        </style>

</head>



<body>

<table width="820" height="1092" border="0" align="center" cellspacing="0">

  <tr bgcolor="#CCCCCC">

    <td colspan="3"><script type="text/javascript">

AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','850','height','240','src','flash/topo','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','flash/topo' ); //end AC code

</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="850" height="240">

      <param name="movie" value="flash/topo.swf" />

      <param name="quality" value="high" />

      <embed src="flash/topo.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="850" height="240"></embed>

    </object></noscript></td>

  </tr>

  <tr bgcolor="#CCCCCC">

    <td width="212" valign="top" bgcolor="#FFFFFF"><table width="200" border="0" cellpadding="0" cellspacing="0" id="fundopesquisa">

      <tr>

        <th width="213" scope="col"><form id="busca_veiculos" name="busca_veiculos" method="post" action="resultado.php">

          <table width="90%" border="0" cellspacing="2" cellpadding="0">

           <tr>

              <td height="41" align="center"> </td>

              <td align="center"> </td>

            </tr>

            <tr>

              <th width="20%" align="center" scope="col"> </th>

              <th width="80%" align="center" scope="col"><span class="dados_detalhes">Marca</span></th>

              </tr>

            <tr>

              <td align="center"> </td>

              <td align="center"><select name="marca" id="marca">
                <?php
do {  
?>
                <option value="<?php echo $row_mascas_lista['marca']?>"><?php echo $row_mascas_lista['marca']?></option>
                <?php
} while ($row_mascas_lista = mysql_fetch_assoc($mascas_lista));
  $rows = mysql_num_rows($mascas_lista);
  if($rows > 0) {
      mysql_data_seek($mascas_lista, 0);
          $row_mascas_lista = mysql_fetch_assoc($mascas_lista);
  }
?>
              </select></td>

              </tr>

            <tr>

              <td align="center"> </td>

              <td align="center"><span class="dados_detalhes">Modelo

                <input type="text" name="modelo" id="modelo" />

              </span></td>

              </tr>

            <tr>

              <td align="center"> </td>

              <td align="center"> </td>

              </tr>

            <tr>

              <td align="center"> </td>

              <td align="right"><input type="submit" name="enviar" id="enviar" value="Buscar" /></td>

              </tr>

            <tr>

              <td align="center"> </td>

              <td align="center"> </td>

            </tr>

          </table>

        </form></th>

      </tr>

    </table>

      <br />

      <table width="200" border="0" cellspacing="0" cellpadding="0">

        <tr>

          <th scope="col"><a href="listar_carros.php"><img src="imagens/btnComprar.png" width="176" height="51" border="0" /><br />

          </a></th>

        </tr>

      </table>

      <br />

      <table width="200" border="0" cellspacing="0" cellpadding="0">

        <tr>

          <th scope="col"><a href="fale_conosco.php"><img src="imagens/btnVender.png" width="176" height="51" border="0" /></a></th>

        </tr>

      </table>

      <br />

      <table width="200" border="0" cellpadding="0" cellspacing="0" id="espaco_ultimos_inseridos">

        <tr>

          <th valign="top" scope="col"><table width="200" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">

            <tr valign="top">

              <th scope="col"><span class="style1">ÚLTIMOS INSERIDOS</span></th>

            </tr>

          </table>

            <?php do { ?>

              <table width="95%" border="0" align="center" cellpadding="2" cellspacing="0">

                <tr>

                  <th scope="col"><hr /></th>

                </tr>

                <tr>

                  <td align="left"><span class="ultimos_cadastros"><a href="detalhes_anuncio.php?id=<?php echo $row_ultimos_cadastrados['id']; ?>"><?php echo $row_ultimos_cadastrados['modelo']; ?></a></span></td>

                </tr>

                <tr>

                  <td align="left" nowrap="nowrap"><span class="ultimos_cadastros">Ano: <?php echo $row_ultimos_cadastrados['ano']; ?></span></td>

                </tr>

              </table>

<?php } while ($row_ultimos_cadastrados = mysql_fetch_assoc($ultimos_cadastrados)); ?>

</th>

        </tr>

      </table>

    </td>

    <td width="616" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="2" cellpadding="0">

      <tr>

        <th scope="col"><h2 class="ultimos_cadastros"><span class="titulos">RESULTADO</span></h2></th>

      </tr>

      <tr>

        <th scope="col"> </th>

      </tr>

      <tr>

        <th align="center" scope="col"> <table border="0">

          <tr>

            <?php

  do { // horizontal looper version 3

?>

              <td width="177"><table width="100" border="0" align="left" cellpadding="0" cellspacing="2">

                <tr>

                  <th scope="col"><a href="detalhes_anuncio.php?id=<?php echo $row_resultado_busca['id']; ?>"><img src="anuncios/<?php echo $row_resultado_busca['foto1']; ?>" width="155" height="109" border="0" /></a></th>

                </tr>

                <tr>

                  <td align="center"><span class="ultimos_cadastros"><strong><a href="detalhes_anuncio.php?id=<?php echo $row_resultado_busca['id']; ?>"><?php echo $row_resultado_busca['modelo']; ?></a></strong></span></td>

                </tr>

                <tr>

                  <td align="center"><span class="ultimos_cadastros"><?php echo $row_resultado_busca['marca']; ?> - <?php echo $row_resultado_busca['modelo']; ?></span></td>

                </tr>

                <tr>

                  <td align="center"><span class="ultimos_cadastros"><?php echo $row_resultado_busca['valor']; ?></span></td>

                </tr>

              </table></td>

              <?php

    $row_empresa = mysql_fetch_assoc($empresa);

    if (!isset($nested_empresa)) {

      $nested_empresa= 1;

    }

    if (isset($row_empresa) && is_array($row_empresa) && $nested_empresa++ % 3==0) {

      echo "</tr><tr>";

    }

  } while ($row_empresa); //end horizontal looper version 3

?>

          </tr>

        </table>

          <table border="0">

            <tr>

              <td><?php if ($pageNum_resultado_busca > 0) { // Show if not first page ?>

                  <a href="<?php printf("%s?pageNum_resultado_busca=%d%s", $currentPage, 0, $queryString_resultado_busca); ?>"><img src="imagens/First.gif" /></a>

                <?php } // Show if not first page ?></td>

              <td><?php if ($pageNum_resultado_busca > 0) { // Show if not first page ?>

                  <a href="<?php printf("%s?pageNum_resultado_busca=%d%s", $currentPage, max(0, $pageNum_resultado_busca - 1), $queryString_resultado_busca); ?>"><img src="imagens/Previous.gif" /></a>

                <?php } // Show if not first page ?></td>

              <td><?php if ($pageNum_resultado_busca < $totalPages_resultado_busca) { // Show if not last page ?>

                  <a href="<?php printf("%s?pageNum_resultado_busca=%d%s", $currentPage, min($totalPages_resultado_busca, $pageNum_resultado_busca + 1), $queryString_resultado_busca); ?>"><img src="imagens/Next.gif" /></a>

                <?php } // Show if not last page ?></td>

              <td><?php if ($pageNum_resultado_busca < $totalPages_resultado_busca) { // Show if not last page ?>

                  <a href="<?php printf("%s?pageNum_resultado_busca=%d%s", $currentPage, $totalPages_resultado_busca, $queryString_resultado_busca); ?>"><img src="imagens/Last.gif" /></a>

                <?php } // Show if not last page ?></td>

              </tr>

          </table>

          </p></th>

      </tr>

    

    </table>      

      <p align="left" class="style1"><br />

    </p></td>

    <td width="18" valign="top" bgcolor="#FFFFFF"> </td>

  </tr>

</table>

<table width="852" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">

  <tr>

    <th bgcolor="#EBEBEB" class="style3" scope="col"><br />

    <?php echo $row_empresa['empresa']; ?> - Todos os Direitos Reservados - <a href="index.php">In&iacute;cio</a> | <a href="empresa.php">Empresa</a> | <a href="listar_carros.php">Carros</a> | <a href="listar_motos.php">Motos</a> | <a href="financiamento.php">Financiamento</a> | <a href="fale_conosco.php">Fale Conosco</a><br />

    <br /></th>

  </tr>

</table>

<p> </p>

</body>

</html>

<?php
mysql_free_result($mascas_lista);


mysql_free_result($resultado_busca);



mysql_free_result($ultimos_cadastrados);



mysql_free_result($destaques);



mysql_free_result($resultado_busca);



mysql_free_result($empresa);



?>

Obrigado e espero que vocês possam me ajudar.

Link para o comentário
Compartilhar em outros sites

5 respostass a esta questão

Posts Recomendados

  • 0
amigo me diz ai qual os campos que você quer pesquisar, e quais os resultados você quer mostrar

ah e qual o nome das tabelas

Para facilitar acesse o site:

http://www.criarstudio.com.br/carros/

ai no campo de busca que fica do lado esquerdo, quando eu efetuo qualquer busca, por exemplo digitando o nome do veiculo ele não aparece no resultado.

Desculpe mais tenho pouco conhecimento em php ainda.

Link para o comentário
Compartilhar em outros sites

  • 0

Os nomes dos campos da tabela na base de dados, estão corretos?

Outra coisa, a função mysql_free result apenas libera a memória usada com o identificador do resultado em uma busca, coisa que não é muito usado, ainda mais levando em consideração que essa função esta "obsoleta".

Link para o comentário
Compartilhar em outros sites

  • 0

Faz o seguinte:

1- Recupera através de um $_GET o valor passado pelos campos da busca. Exemplo: O usuário escolhe Marca e Modelo, então você cria duas variáveis na página que executará a busca e recupera o valor assim $varMarca = $_GET['marca']; $varModelo = $_GET['modelo'];

2- Faça uma pequena guambiarra para executar a sua busca. Exemplo:

$Complemento = 1; //guambiarra

if($varModelo){ // Se acontecer a variável

$Complemento .= " AND modelo= '$varModelo' "; // Adiciona ao valor de complemento o que está entre aspas

}

if($varMarca){ // Se acontecer a variável

$Complemento .= " AND marca= '$arMarca' "; // Adiciona ao valor de complemento o que está entre aspas

}

// Agora o valor de complemento será "1 AND = '$varModelo' AND marca= '$arMarca''

Como você usou o Dreamweaver procura o script e muda ele para:

$query_Busca = sprintf("SELECT * FROM marcas WHERE 1=$Complemento ORDER BY modelo = 'Fiat'"); //Onde você ver 1=$complemento é ainda aquela "guambiarra"

Bom, é simples e fácil de se fazer. Faço isso a muito tempo e tem sempre dado certo.

Obs.: esse script foi criado com a ajuda de Edgar Serra, o Moderador ESerra. Valeu!

Outra coisa!! Se você for usar o que eu te passei você terá q apagar algumas coisas que o DW inseriu para dar certo. Coisas como aquelas que ele inseriu para a busca que você programou nele mesmo. Um ponto importate que eu notei no seu post é que você passou muitos dados que não deveria passar. não exponha muito o seu codigo, afinal, todos poderao vê-lo a partir de agora e mais alguém poderá te prejudicar. Crie situações hipotéticas para fazer peguntas, utilize sempre exemplos genéricos... Exemplo: Como faço para criar uma busca em dois campos de uma tabela, os os campos digitados serão apenas texto? Digo isso como sugestão... Boa sorte!

Link para o comentário
Compartilhar em outros sites

  • 0

pra fazer isso dinamicamente da pra fazer em ajax em php teria que carregar a pág novamente pra fazer a consulta vo ver o que posto amanha hj to cansado

<?php
session_start();
$_SESSION['Marcas']=$_POST['Marcas'];
$modelo=$_SESSION['Marcas'];

                        include "Base.php";//aqui é a conexão com sua base de dados
                        $result = mysql_query("select marca from SUA_TABELA order by marca;",$conexao);
                        
                        $Quantos = mysql_num_rows($result);
                        $i=0;
                        echo '<form id="form1" name="form1" method="post" action="">
                        <SELECT NAME="Marcas">';
                        if(!$modelo)
                        {
                        echo '<OPTION value="0" SELECTED>Selecione um Marca</option>';
                        }
                        else
                        {
                            echo '<OPTION value="'.$modelo.'" SELECTED>'.$modelo.'</option>';
                        }
                        for ($i==0; $i<$Quantos; $i++)
                        {
                            
                            $marca = mysql_result($result,$i,"marca");
                            echo "<OPTION value=".$marca.">".$marca."</option>";
                        }
                        echo'</select>
                        <input type="submit" name="Submit" value="ok" /><br>
                        <SELECT NAME="Modelo">
                        ';
                        if ($_SESSION['Marcas'])
                        {
                            echo '<OPTION value="0" SELECTED>Selecione um modelo</option>';
                        $result = mysql_query("select modelo from SUA_TABELA where modelo='$modelo' order by modelo;",$conexao);
                        $Quantos = mysql_num_rows($result);
                            $i=0;
                            for ($i==0; $i<$Quantos; $i++)
                                {
                            
                                    $modelo = mysql_result($result,$i,"modelo");
                                    echo "<OPTION value=".$modelo.">".$modelo."</option>";
                                }

                        }
                        else
                        {
                            echo '<OPTION value="0" SELECTED>---------------</option>';
                        }
                        echo'</form>';
                        
                
                    ?>

ta ai amigo seleciona a marca aperta ok ele vai carregar a página d novo com as devidas marcas no select d baixo depois é definir a ação que ocorre depois de selecionar o modelo

Editado por DiegoCipriano
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,1k
    • Posts
      651,8k
×
×
  • Criar Novo...