Jump to content

mysqli_fetch_array


Recommended Posts

Posted
!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
      <title></title>
</head>
<body>  
     <?php
        $host = 'localhost';
        $user = 'root';
        $senha = '';
        $bdados = 'Empresa';

        // Código de ligação

        $cnx = new mysqli ($host,$user,$senha,$bdados);
        if ($cnx->connect_errno) {
        print ("Não foi possivel ligar à Base de Dados: ".$cnx->connect_error);
        }else{
        //print "Ligação à base de dados efectuada com sucesso!"; 
        echo "<br>";
        }

        $nif = $_POST['nif'];
        //echo $palavra;

        $sql = mysqli_query($cnx,"SELECT Nome,Nascido,ECivil,Profissao,Situacao,EntExterna,NumEntExt,Pai,Mae,Distrito,Concelho,Freguesia,Outro0,Nif,CCidadao,SSocial,Outro1,Telefone,Telemovel,Email,S_Email,Morada,Lugar,CPostal,Obs, NomeAgre,NascidoAgre,RelacaoAgre,ContactoAgre
	 FROM Clientes
	 JOIN Agregado ON Clientes.ID_Cliente=Agregado.Fk_CliAgre
	  WHERE Nif ='123456789'");

         while ($linha = mysqli_fetch_array($sql)) 
        {
            $Cliente = $linha ['ID_Cliente']; 
            $Nome = $linha ['Nome'];
            $Nascido = $linha ['Nascido']; 
            $ECivil = $linha ['ECivil']; 
            $Profissao = $linha ['Profissao'];  
            $Situacao = $linha ['Situacao'];
            $EntExt = $linha ['EntExterna'];
            $NumEntExt =$linha ['NumEntExt'];
            $Pai = $linha ['Pai'];
            $Mae = $linha ['Mae'];
            $Distrito = $linha ['Distrito']; 
            $Concelho = $linha ['Concelho'];
            $Freguesia = $linha ['Freguesia'];
            $Outro0 = $linha ['Outro0'];
            $Nif = $linha ['Nif'];
            $CCidadao = $linha ['CCidadao'];
            $SSocial = $linha ['SSocial'];
            $Outro1 = $linha ['Outro1'];
            $Telefone = $linha ['Telefone'];
            $Telemovel = $linha ['Telemovel'];
            $Email = $linha ['Email'];
            $S_Email = $linha ['S_Email'];
            $Morada = $linha ['Morada'];
            $Lugar = $linha ['Lugar'];
            $CPostal = $linha ['CPostal'];
            $Obs = $linha ['Obs'];
//
            $AgreNome = $linha ['NomeAgre'];
            $AgreNascido = $linha ['NascidoAgre'];
            $AgreRelacao = $linha['RelacaoAgre'];
            $AgreContacto = $linha ['ContactoAgre'];

        }
     ?>
     <br>
    <div id="queryCliente" style="background: #B6B6BC; width:960px; margin: 0 auto; height: 335px; padding:2px;margin-top: -40px;">
        <fieldset class="" style= "border: solid 1px; border-color: #fff; width:928px; margin-left: 10px; padding: 3px;">
            Cliente: <input class="cxtexto" type="text" name="" value="<?php print $Cliente ?>" style="width: 50px; text-align: center; height: 20px;">
            Nome: <input type="text" name="" required="" value="<?php print $Nome ?>" style="width: 407px; height: 20px;">
            Nascido a: <input class="cxtexto" type="datetime" name="" value="<?php print $Nascido ?>" style="width:105px; text-align: center; height: 20px;">
            ECivil: <input class="cxtexto" type="text" name="" value="<?php print $ECivil ?>" style="width: 105px; height: 20px;"> <br>
            Profissão: <input class="cxtexto" type="text" name="" value="<?php print $Profissao ?>" style="width: 185px; height: 20px;">
            Situação: <input class="cxtexto" type="text" name="" value="<?php print $Situacao ?>" style="width: 115px; height: 20px;">
            EntExterna: <input class="cxtexto" type="text" name="" value="<?php print $EntExt ?>" style="width: 160px; height: 20px;">
            NumEntExt: <input class="cxtexto" type="text" name="" value="<?php print $NumEntExt ?>" style="width: 120px; height: 20px;">
        </fieldset>
        <fieldset class="" style="border: solid 1px; border-color:#fff; margin-top: 3px; width:928px; margin-left:10px; padding: 3px;">
            Pai: <input type="text" name="" id="txPai" value="<?php print $Pai ?>" style="width: 423px; height: 20px;">
            Mãe: <input type="text" name="" id="txMae" value="<?php print $Mae ?>" style="width: 423px; height: 20px;">
      </fieldset>
      <fieldset class="" style="border: solid 1px; border-color:#fff; margin-top: 3px; width: 300px;text-align: left; padding: 3px; margin-left: 10px;">
            Distrito: <input class="cxtexto" type="text" value="<?php print $Distrito ?>" style=" width: 212px;margin-left: 19px; height: 20px;"><br>
            Concelho: <input class="cxtexto" type="text" name="" value="<?php print $Concelho ?>" style="width:212px; margin-left:3px; height: 20px;"><br>
            Freguesia: <input class="cxtexto" type="text" name="" value="<?php print $Freguesia ?>" style="width:212px; margin-left:1px; height: 20px;">
            Outro: <input class="cxtexto" type="text" name="" value="<?php print $Outro0 ?>" style="width:212px; margin-left:32px; height: 20px;">
      </fieldset>
      <fieldset class="" style="border: solid 1px; border-color:#fff; width: 300px; margin-left: 323px; margin-top: -108px;text-align: left; padding: 3px;">
            Nif: <input class="cxtexto" type="text" name="" value="<?php print $Nif ?>" style="width:210px; margin-left:50px; height: 20px;"> <br>
            CCidadão: <input class="cxtexto" type="text" name="" value="<?php print $CCidadao ?>" style="width:210px; height: 20px;"> <br>
            SSocial: <input class="cxtexto" type="text"name="" value="<?php print $SSocial ?>" style="width:210px;margin-left:18px; height: 20px;">
            Outro: <input class="cxtexto" type="text" name="" value="<?php print $Outro1 ?>" style="width:210px;margin-left:32px; height: 20px;">
      </fieldset>
      <fieldset style="border: solid 1px; border-color:#fff; margin-top: 5px; width: 300px; margin-left: 638px;margin-top: -108px;text-align: left; padding: 3px;">
            Telefone: <input class="cxtexto" type="text" name="" value="<?php print $Telefone ?>" style="width:205px;margin-left:13px; height: 20px;">
            Telemovel: <input class="cxtexto" type="text" name="" value="<?php print $Telemovel ?>" style="width:205px; height: 20px;">
            Email: <input class="cxtexto" type="email" name="" value="<?php print $Email?>" style="width:205px;margin-left:36px; height: 20px;">
            Senha: <input class="cxtexto" type="email" name="" value="<?php print $S_Email ?>" style="width:205px; margin-left:31px; height: 20px;">
      </fieldset>
      <fieldset class="" style="text-align: left; border: solid 1px; border-color: #fff; margin-top: 3px; width:928px; margin-left: 10px; padding: 3px;">
            Morada: <input type="text" name="" value="<?php print $Morada ?>" style="width: 345px; height: 20px;">
            Lugar: <input type="text" name="" value="<?php print $Lugar ?>" style="width: 195px; height: 20px;">
            CPostal: <input type="text" name="" value="<?php print $CPostal ?>" style="width: 195px; height: 20px;">
      </fieldset>
      <fieldset style="margin-left: 10px; width: 929px; height: 85px; border: solid 1px; border-color: #fff; margin-top: 3px; padding: 2px;">
            <textarea name="" rows="3" cols="100"><?php print $Obs ?></textarea>
      </fieldset>
    </div>
    <br>
    <div id="Agregado">
    <header>
	<div class="alert alert-info"></div>
	</header>
	<div id="agregado">
	<section>
		<table class="col-md-12">
			<tr class="bg-primary" align="center">
				<th class="pad-basic">Nome</th>
				<th class="pad-basic">Nascido</th>
				<th class="pad-basic">Relação</th>
				<th class="pad-basic">Contacto</th>
			</tr>
<?php
	
	
		echo
		'<tr>
			<td>'.$AgreNome.'</td>
			<td>'.$AgreNascido.'</td>
			<td>'.$AgreRelacao.'</td>
			<td>'.$AgreContacto.'</td>
		</tr>';
		
?>
		</table>
	</section>
</div>		
</div>
</div>
</body>
</html>      

Sou apenas curioso da programação

Estou a cria uma pequena aplicação em html/php passei a parte de inserir dados agora pretendo pesquisa-los.

Objectivamente tenho um agregado familiar (Pai, esposa e filhos), para mostrar os dados tenho um formulário e uma tabela

ao efectuar a busca mostra-me o "Pai", mas apenas o último dos "filhos" creio que o problema está neste laço

while ($linha = mysqli_fetch_array($sql))

Será possível explicarem-me como contornar o problema? Obrigado.

Posted
12 horas atrás, Azelha disse:

mas apenas o último dos "filhos" creio que o problema está neste laço

while ($linha = mysqli_fetch_array($sql))

Será possível explicarem-me como contornar o problema? Obrigado.

Ola...

tenta colocar o bloco 

<div id="queryCliente" ... </div>

dentro do laço.

Atenciosamente

Ricardo

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.