Ir para o conteúdo
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

tbesteves

Combobox dinamico

Mensagens Recomendadas

tbesteves

Nao estou a conseguir que quando escolha a marca ele mostre o respectibvo modelo, o codigo e o seguinte:

tenho a tabela marca (cod_marca, marca) a tabela modelo(cod_modelo,modelo) e a tabela marca_modelo(cod_marca,cod_modelo) que relacciona a marca com o modelo

<?php require_once('Connections/marca.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;
}
}

mysql_select_db($database_marca, $marca);
$query_pesq = "SELECT * FROM marca";
$pesq = mysql_query($query_pesq, $marca) or die(mysql_error());
$row_pesq = mysql_fetch_assoc($pesq);
$totalRows_pesq = mysql_num_rows($pesq);

mysql_select_db($database_marca, $marca);
$query_modelo = "SELECT * FROM modelo  INNER JOIN marca_modelo  ON modelo.cod_modelo=marca_modelo.cod_marca";
$modelo = mysql_query($query_modelo, $marca) or die(mysql_error());
$row_modelo = mysql_fetch_assoc($modelo);
$totalRows_modelo = mysql_num_rows($modelo);

mysql_select_db($database_marca, $marca);
$query_combustivel = "SELECT * FROM combustivel";
$combustivel = mysql_query($query_combustivel, $marca) or die(mysql_error());
$row_combustivel = mysql_fetch_assoc($combustivel);
$totalRows_combustivel = mysql_num_rows($combustivel);

$colname_res = "-1";
if (isset($_POST['cod_marca'])) {
  $colname_res = $_POST['cod_marca'];
}
mysql_select_db($database_marca, $marca);
$query_res = sprintf("SELECT * FROM marca WHERE cod_marca = %s", GetSQLValueString($colname_res, "int"));
$res = mysql_query($query_res, $marca) or die(mysql_error());
$row_res = mysql_fetch_assoc($res);
$totalRows_res = mysql_num_rows($res);
?>
<style type="text/css">
<!--
#apDiv4 {	position:absolute;
left:299px;
top:596px;
width:72px;
height:25px;
z-index:1;
visibility: visible;
}
.pesquisa {
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
}
.pesq {
font-size: 18px;
}
#apDiv1 {
position:absolute;
left:248px;
top:545px;
width:59px;
height:25px;
z-index:1;
}
-->
</style>
<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<div id="apDiv1">
  <form action="index.php?pag=resultados" method="post" name="form1" id="form1">
    <input type="submit" name="pesquisar" id="pesquisar" value="Pesquisar" />
  </form>
</div>
<p> </p>

<table width="800" border="0">
  <tr>
    <td height="755"><form id="form2" name="form2" method="get" action="index.php?pag=resultados">
      <table width="800" border="0">
        <tr align="left" valign="top">
          <th height="749"><p class="pesq">Pesquise a sua próxima viatura entre as mais diversas existentes. </p>
            <p class="pesq">Você indica o que pretende nós fazemos o resto.</p>
            <p class="pesq"> </p>
            <p class="pesq"><span class="pesquisa">Pesquisa Rápida </span></p>
            <table width="59%" height="546" border="0" align="right" id="destaques2">
              <tr>
                <td height="229" colspan="3" align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="456" height="228" id="FlashID" title="ferrari">
                  <param name="movie" value="Videos/ferrari.swf" />
                  <param name="quality" value="high" />
                  <param name="wmode" value="transparent" />
                  <param name="swfversion" value="6.0.65.0" />
                  <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                  <param name="expressinstall" value="Scripts/expressInstall.swf" />
                  <param name="SCALE" value="exactfit" />
                  <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                  <!--[if !IE]>-->
                  <object type="application/x-shockwave-flash" data="Videos/ferrari.swf" width="456" height="228">
                    <!--<![endif]-->
                    <param name="quality" value="high" />
                    <param name="wmode" value="transparent" />
                    <param name="swfversion" value="6.0.65.0" />
                    <param name="expressinstall" value="Scripts/expressInstall.swf" />
                    <param name="SCALE" value="exactfit" />
                    <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                    <div>
                      <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
                      <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
                      </div>
                    <!--[if !IE]>-->
                    </object>
                  <!--<![endif]-->
                  </object></td>
                </tr>
              <tr>
                <td height="29" colspan="3" align="center"><span class="pesq">Ferrari</span></td>
                </tr>
              <tr>
                <td width="34%" height="102" align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="136" height="96" id="FlashID2" title="opel">
                  <param name="movie" value="Videos/opel.swf" />
                  <param name="quality" value="high" />
                  <param name="wmode" value="transparent" />
                  <param name="swfversion" value="6.0.65.0" />
                  <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                  <param name="expressinstall" value="Scripts/expressInstall.swf" />
                  <param name="SCALE" value="exactfit" />
                  <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                  <!--[if !IE]>-->
                  <object type="application/x-shockwave-flash" data="Videos/opel.swf" width="136" height="96">
                    <!--<![endif]-->
                    <param name="quality" value="high" />
                    <param name="wmode" value="transparent" />
                    <param name="swfversion" value="6.0.65.0" />
                    <param name="expressinstall" value="Scripts/expressInstall.swf" />
                    <param name="SCALE" value="exactfit" />
                    <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                    <div>
                      <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
                      <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
                      </div>
                    <!--[if !IE]>-->
                    </object>
                  <!--<![endif]-->
                  </object></td>
                <td width="33%" align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="136" height="96" id="FlashID3" title="audi">
                  <param name="movie" value="Videos/audi.swf" />
                  <param name="quality" value="high" />
                  <param name="wmode" value="transparent" />
                  <param name="swfversion" value="6.0.65.0" />
                  <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                  <param name="expressinstall" value="Scripts/expressInstall.swf" />
                  <param name="SCALE" value="exactfit" />
                  <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                  <!--[if !IE]>-->
                  <object type="application/x-shockwave-flash" data="Videos/audi.swf" width="136" height="96">
                    <!--<![endif]-->
                    <param name="quality" value="high" />
                    <param name="wmode" value="transparent" />
                    <param name="swfversion" value="6.0.65.0" />
                    <param name="expressinstall" value="Scripts/expressInstall.swf" />
                    <param name="SCALE" value="exactfit" />
                    <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                    <div>
                      <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
                      <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
                      </div>
                    <!--[if !IE]>-->
                    </object>
                  <!--<![endif]-->
                  </object></td>
                <td width="33%" align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="136" height="96" id="FlashID4" title="alfa">
                  <param name="movie" value="Videos/alfa.swf" />
                  <param name="quality" value="high" />
                  <param name="swfversion" value="6.0.65.0" />
                  <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                  <param name="expressinstall" value="Scripts/expressInstall.swf" />
                  <param name="SCALE" value="exactfit" />
                  <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                  <!--[if !IE]>-->
                  <object type="application/x-shockwave-flash" data="Videos/alfa.swf" width="136" height="96">
                    <!--<![endif]-->
                    <param name="quality" value="high" />
                    <param name="swfversion" value="6.0.65.0" />
                    <param name="expressinstall" value="Scripts/expressInstall.swf" />
                    <param name="SCALE" value="exactfit" />
                    <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                    <div>
                      <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
                      <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
                      </div>
                    <!--[if !IE]>-->
                    </object>
                  <!--<![endif]-->
                  </object></td>
                </tr>
              <tr>
                <td height="33" align="center"><span class="pesq">Opel corsa</span></td>
                <td align="center"><span class="pesq">Audi A6</span></td>
                <td align="center"><span class="pesq">Alfa Romeu</span></td>
                </tr>
              <tr>
                <td height="102" align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="136" height="96" id="FlashID5" title="toyota">
                  <param name="movie" value="Videos/toyota.swf" />
                  <param name="quality" value="high" />
                  <param name="wmode" value="transparent" />
                  <param name="swfversion" value="6.0.65.0" />
                  <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                  <param name="expressinstall" value="Scripts/expressInstall.swf" />
                  <param name="SCALE" value="exactfit" />
                  <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                  <!--[if !IE]>-->
                  <object type="application/x-shockwave-flash" data="Videos/toyota.swf" width="136" height="96">
                    <!--<![endif]-->
                    <param name="quality" value="high" />
                    <param name="wmode" value="transparent" />
                    <param name="swfversion" value="6.0.65.0" />
                    <param name="expressinstall" value="Scripts/expressInstall.swf" />
                    <param name="SCALE" value="exactfit" />
                    <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                    <div>
                      <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
                      <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
                      </div>
                    <!--[if !IE]>-->
                    </object>
                  <!--<![endif]-->
                  </object></td>
                <td align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="136" height="96" id="FlashID6" title="nissan">
                  <param name="movie" value="Videos/nissan.swf" />
                  <param name="quality" value="high" />
                  <param name="wmode" value="transparent" />
                  <param name="swfversion" value="6.0.65.0" />
                  <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                  <param name="expressinstall" value="Scripts/expressInstall.swf" />
                  <param name="SCALE" value="exactfit" />
                  <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                  <!--[if !IE]>-->
                  <object type="application/x-shockwave-flash" data="Videos/nissan.swf" width="136" height="96">
                    <!--<![endif]-->
                    <param name="quality" value="high" />
                    <param name="wmode" value="transparent" />
                    <param name="swfversion" value="6.0.65.0" />
                    <param name="expressinstall" value="Scripts/expressInstall.swf" />
                    <param name="SCALE" value="exactfit" />
                    <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                    <div>
                      <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
                      <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
                      </div>
                    <!--[if !IE]>-->
                    </object>
                  <!--<![endif]-->
                  </object></td>
                <td align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="136" height="96" id="FlashID7" title="mini">
                  <param name="movie" value="Videos/mini.swf" />
                  <param name="quality" value="high" />
                  <param name="wmode" value="transparent" />
                  <param name="swfversion" value="6.0.65.0" />
                  <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                  <param name="expressinstall" value="Scripts/expressInstall.swf" />
                  <param name="SCALE" value="exactfit" />
                  <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                  <!--[if !IE]>-->
                  <object type="application/x-shockwave-flash" data="Videos/mini.swf" width="136" height="96">
                    <!--<![endif]-->
                    <param name="quality" value="high" />
                    <param name="wmode" value="transparent" />
                    <param name="swfversion" value="6.0.65.0" />
                    <param name="expressinstall" value="Scripts/expressInstall.swf" />
                    <param name="SCALE" value="exactfit" />
                    <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                    <div>
                      <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
                      <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
                      </div>
                    <!--[if !IE]>-->
                    </object>
                  <!--<![endif]-->
                  </object></td>
                </tr>
              <tr>
                <td height="37" align="center"><span class="pesq">Toyota Corolla</span></td>
                <td align="center"><span class="pesq">Nissan Patrol</span></td>
                <td align="center"><span class="pesq">Mini One</span></td>
                </tr>
              <tr> </tr>
              <tr> </tr>
              <tr> </tr>
              <tr> </tr>
              <tr> </tr>
              <tr> </tr>
              </table>
              <p>Marca <span class="pesquisa-rapida">
             <select name="marca" id="marca" selected"">
               <option value="" selected="selected" <?php if (!(strcmp("", $row_pesq['cod_marca']))) {echo "selected=\"selected\"";} ?> selected="<?php $m=1 ?>"></option>
<?php 
do {  
?>
               <option value="<?php echo $row_pesq['cod_marca']?>"<?php if (!(strcmp($row_pesq['cod_marca'], $row_pesq['cod_marca']))) {echo "selected=\"selected\"";} ?>><?php echo $row_pesq['marca']?></option>
               <?php
		   } while ($row_pesq = mysql_fetch_assoc($pesq));
  $rows = mysql_num_rows($pesq);
  if($rows > 0) {
      mysql_data_seek($pesq, 0);
  $row_pesq = mysql_fetch_assoc($pesq);
   }
?>
              </select>
              </span></p>
            <p>Modelo<span class="pesquisa-rapida">
              <select name="modelo" id="modelo">
              <option value="" selected="selected"></option>

<?php 
mysql_select_db("standonline",$marca);
$string_pesquisa="SELECT        modelo.cod_modelo, modelo.modelo
FROM            (modelo INNER JOIN
                         marca_modelo ON modelo.cod_modelo = marca_modelo.cod_modelo)
WHERE        (marca_modelo.cod_marca ='{$m}')";
$resultado=mysql_query($string_pesquisa,$marca);
$registo=mysql_fetch_row($resultado);



while ($registo) {
    echo "<option value='$registo[0]'>$registo[1]</option>";
    $registo=mysql_fetch_row($resultado);
    }
  
?>
              </select>
              </span></p>
            <p>Combustível<span class="pesquisa-rapida">
              <select name="combustivel" id="combustivel">
              <option value="" selected="selected"></option>
                <?php
do {  
?>
                <option value="<?php echo $row_combustivel['combustivel']?>"<?php if (!(strcmp($row_combustivel['combustivel'], $row_combustivel['combustivel']))) {echo "selected=\"selected\"";} ?>><?php echo $row_combustivel['combustivel']?></option>
                <?php
} while ($row_combustivel = mysql_fetch_assoc($combustivel));
  $rows = mysql_num_rows($combustivel);
  if($rows > 0) {
      mysql_data_seek($combustivel, 0);
  $row_combustivel = mysql_fetch_assoc($combustivel);
  }
?>
              </select>
              </span></p>
            <p>Preço de <span id="spryselect1">
              <select name="min" id="min">
                <option value="" selected="selected"></option>
                <option value="250">250</option>
                <option value="500">500</option>
                <option value="1000">1 000</option>
                <option value="2000">2 000</option>
                <option value="3000">3 000</option>
                <option value="4000">4 000</option>
                <option value="5000">5 000</option>
                <option value="6000">6 000</option>
                <option value="7000">7 000</option>
                <option value="8000">8 000</option>
                <option value="9000">9 000</option>
                <option value="10000">10 000</option>
                <option value="12000">12 000</option>
                <option value="14000">14 000</option>
                <option value="16000">16 000</option>
                <option value="18000">18 000</option>
                <option value="20000">20 000</option>
                <option value="22000">22 000</option>
                <option value="24000">24 000</option>
                <option value="26000">26 000</option>
                <option value="28000">28 000</option>
                <option value="30000">30 000</option>
                <option value="32000">32 000</option>
                <option value="34000">34 000</option>
                <option value="36000">36 000</option>
                <option value="38000">38 000</option>
                <option value="40000">40 000</option>
                <option value="50000">50 000</option>
                <option value="60000">60 000</option>
                <option value="70000">70 000</option>
                <option value="80000">80 000</option>
                <option value="90000">90 000</option>
                <option value="100000">100 000</option>
                <option value="150000">150 000</option>
                <option value="200000">200 000</option>
                <option value="250000">250 000</option>
                <option value="300000">300 000</option>
                <option value="350000">350 000</option>
                <option value="400000">400 000</option>
                <option value="450000">450 000</option>
                <option value="500000">500 000</option>
              </select>
              <span class="selectRequiredMsg">Please select an item.</span></span> a <span id="spryselect2">
                <select name="max" id="max">
                <option value="" selected="selected"></option><option value="250">250</option><option value="500">500</option><option value="1000">1 000</option><option value="2000">2 000</option><option value="3000">3 000</option><option value="4000">4 000</option><option value="5000">5 000</option><option value="6000">6 000</option><option value="7000">7 000</option><option value="8000">8 000</option><option value="9000">9 000</option><option value="10000">10 000</option><option value="12000">12 000</option><option value="14000">14 000</option><option value="16000">16 000</option><option value="18000">18 000</option><option value="20000">20 000</option><option value="22000">22 000</option><option value="24000">24 000</option><option value="26000">26 000</option><option value="28000">28 000</option><option value="30000">30 000</option><option value="32000">32 000</option><option value="34000">34 000</option><option value="36000">36 000</option><option value="38000">38 000</option><option value="40000">40 000</option><option value="50000">50 000</option><option value="60000">60 000</option><option value="70000">70 000</option><option value="80000">80 000</option><option value="90000">90 000</option><option value="100000">100 000</option><option value="150000">150 000</option><option value="200000">200 000</option><option value="250000">250 000</option><option value="300000">300 000</option><option value="350000">350 000</option><option value="400000">400 000</option><option value="450000">450 000</option><option value="500000">500 000</option>
</select>
              <span class="selectRequiredMsg">Please select an item.</span></span></p>
            <p> </p>
            <p><a href="index.php?pag=pesquisar">Pesquisa Avançada</a></p></th>
</tr>
        </table>
    </form></td>
  </tr>
</table>
<script type="text/javascript">
<!--
swfobject.registerObject("FlashID4");
swfobject.registerObject("FlashID3");
swfobject.registerObject("FlashID2");
swfobject.registerObject("FlashID");
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2");
swfobject.registerObject("FlashID7");
swfobject.registerObject("FlashID5");
swfobject.registerObject("FlashID6");
//-->
</script>
<?php
mysql_free_result($pesq);

mysql_free_result($modelo);

mysql_free_result($combustivel);

mysql_free_result($res);
?>
<?php

?>

Partilhar esta mensagem


Ligação para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!

Registar nova conta

Entra

Já tem conta? Inicie sessão aqui.

Entrar Agora

×

Aviso Sobre Cookies

Ao usar este site você aceita os nossos Termos de Uso e Política de Privacidade. Este site usa cookies para disponibilizar funcionalidades personalizadas. Para mais informações visite esta página.