Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Danielxv

Problema ao consultar varias tabelas

Recommended Posts

Objetivo:

Criar duas drop down box para filtrar a busca, mais especificamente, em qual tabela buscar as informações.

Drop down box 1 seleciona a tabela, drop down box 2 busca as informações.

Problema:

Não consigo fazer drop down box 2 buscar na tabela informada na drop down box 1.

 

O que foi tentado:

Utilizar variável para o nome da tabela, pelo que eu li parece não ser possível.

Utilizar 'if' para a escolha do 'SELECT' com a tabela correta, não consegui pois sempre causava erro na continuidade do comando.

 

Sei que sou eu que estou deixando de fazer algo ou fazendo algo errado, mas não estou conseguindo.

Quem pude me ajudar, eu agradeço.

 

 

Codigo criado ate agora:

A parte onde tem "*******************" seria o nome da tabela.

<?
	mysql_connect("*","*","*");
	mysql_select_db("*");
	
	if(isset($select)&&$select!="")
		{
		$select=$_GET['select'];
		}
?>

<?
$estado=$_GET['estado'];
?>
<select name="select" size=1 value="2" onChange="getStates(this);">
<option value="">Selecione o estado</option>
<option value="1" <? if ($estado==1){ echo "SELECTED";} ?> >Acre</option>
<option value="2" <? if ($estado==2){ echo "SELECTED";} ?> >Tocantins</option>
</select> 
<script Language="JavaScript">
function getStates(what) {
 if (what.selectedIndex != '') {
 	var estado = what.value;
 	document.location=('index.php?estado=' + estado);
 }
}
</Script> 
<?php
if ($estado==1){ ?>
<form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> ">
Nome :
<select name="select">
<option value="">--- Selecione um nome ---</option>
<?

	$list=mysql_query("select * from acre order by nome_completo asc");
	while($row_list=mysql_fetch_assoc($list))
		{

			?>
				<option value="<? echo $row_list['nome_completo']; ?>" <? if($row_list['nome_completo']==$select){ echo "selected"; } ?>><? echo $row_list['nome_completo']; ?></option>
			<?

		}

?>
</select>
<input type="submit" name="Submit" value="Selecionar" />
</form>


<?php
}
?>

<?php
if ($estado==2){ ?>
<form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> ">
Nome :
<select name="select">
<option value="">--- Selecione um nome ---</option>
<?

	$list=mysql_query("select * from tocantins order by nome_completo asc");
	while($row_list=mysql_fetch_assoc($list))
		{

			?>
				<option value="<? echo $row_list['nome_completo']; ?>" <? if($row_list['nome_completo']==$select){ echo "selected"; } ?>><? echo $row_list['nome_completo']; ?></option>
			<?

		}

?>

</select>
<input type="submit" name="Submit" value="Selecionar" />
</form>

<?php
} ?> 

<p>

<?
	if(isset($select)&&$select!=""){
	$result=mysql_query("select * from ******************* where nome_completo='$select'");
	$row=mysql_fetch_assoc($result);
?>
<table border="0" width="100%" id="table3">
	<tr>
		<td width="99%">
 		<font face="Verdana">
				Estado: <strong><? echo $row['estado']; ?></strong>
 	

				Sexo: <strong><? echo $row['sexo']; ?></strong>
 	

				Data Nascimento: <strong><? echo $row['data_nascimento']; ?></strong>
 	

				Estado Civil: <strong><? echo $row['estado_civil']; ?></strong>
 	

				Ocupação: <strong><? echo $row['ocupacao']; ?></strong>
			</font>
 	</td>
	</tr>

</table>
<?
}
mysql_close();
?>
</p>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.