Ir para conteúdo

Arquivado

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

teteuvec

Escrever resultado de pesquisa do mysql utilizando while

Recommended Posts

Prezados boa tarde,

 

Estou tentando escrever na tela o resultado de um select na tela utilizando WHILE, porém está entrando em loop infinito e gostaria de ajuda para acertar a sintaxe desta técnica.

 

 

Código apenas com 1 WHILE

<?php
				$_SESSION['DB_base'] = 'tupa';
				$_SESSION['table_base'] = 'people_records';
				$query_Recordset2 = "SELECT * FROM {$_SESSION['table_base']} WHERE `link_record` = {$data1['id']} AND `record_caracter_id` = 1 order by {$_SESSION['id_base']} DESC";
				$Recordset2 = mysqli_query($connect, $query_Recordset2) or die(mysqli_error($connect));
				$row_Recordset2 = mysqli_fetch_assoc($Recordset2);
				$totalRows_Recordset2 = mysqli_num_rows($Recordset2);
				while($Recordset2 = mysqli_fetch_assoc($Recordset2)) {
					echo "Contato: ".$Recordset2["name"]."</br>";
					echo "CPF/CNPJ: ".$Recordset2["cpf_cnpj"]."</br>";
					echo "e-mail: ".$Recordset2["email"]."</br>";
					echo "Celular: ".$Recordset2["cellphone"]."</br>";
					echo "Telefone: ".$Recordset2["telephone"]."</br>";
					echo "Documento de identificação: ".$Recordset2["name"]."</br>";
					echo "</br>";
				}?>

 

 

Código inteiro:

<?php
session_start();
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];
$_SESSION['del_message'] = 'Deseja excluir o cliente ';
$_SESSION['DB_base'] = 'tupa';
$_SESSION['table_base'] = 'people_records';
$_SESSION['id_base'] = 'id';
require_once('connections.php');
$query_Recordset1 = "SELECT * FROM {$_SESSION['table_base']} WHERE record_caracter_id = '0' order by {$_SESSION['id_base']} DESC";
$Recordset1 = mysqli_query($connect, $query_Recordset1) or die(mysql_error());
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);
?>

<!doctype html>
<html lang='pt-br'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tupã - Serviços de Engenharia</title>

<link href='css/sistema.css' rel='stylesheet' type='text/css'
	media='all'>

<style type="text/css">
#cnpj {
	display: none;
}

#contato {
	display: none;
}

#endereco {
	display: none;
}
</style>
</head>
<body>
	<fieldset>
		<legend>Gerenciamento de Clientes</legend>
		<table id="tabela">
			<thead>
				<tr>
					<th>Descrição</th>
					<th>Contato</th>
					<th>Projetos</th>
					<th colspan="3">Ação</th>
				</tr>
				<tr>
					<th></th>
					<th></th>
					<th></th>
					<th colspan="3"><input type="submit" value="Filtrar" /> | <input
						type="button" onclick="javascript: location.href='#rec_openModal'"
						value="Adicionar" /></th>
				</tr>
			</thead>
			<?php while ($Recordset1 = $row_Recordset1){?>
			<tr>
				<td bgcolor="#F5F5F5"><p>
						Código:
						<?php echo $Recordset1['id']; ?>
						<br /> Cliente:
						<?php echo $Recordset1['name']; ?>
						<br /> CPF/CNPJ:
						<?php echo $Recordset1['cpf_cnpj']; ?>
						<br /> e-mail:
						<?php echo $Recordset1['email']; ?>
						<br /> Celular:
						<?php echo $Recordset1['cellphone']; ?>
						<br /> Telefone:
						<?php echo $Recordset1['telephone']; ?>
						<br /> Documento de identificação:
						<?php
						if(file_exists('imagens/clients/energy_bill/'.$Recordset1['id'].'.jpg'))
						{
							echo 'Documento de identificação: <a href=imagens/clients/energy_bill/'.$Recordset1['id'].'.jpg target="_blank"><img src="imagens/view.png" width="24" height="24">';
						}
						else
						{
							echo 'Documento de identificação: indisponível';
						}
						?>
					</p></td>
				<td bgcolor="#F5F5F5"><?php
				$_SESSION['DB_base'] = 'tupa';
				$_SESSION['table_base'] = 'people_records';
				$query_Recordset2 = "SELECT * FROM {$_SESSION['table_base']} WHERE `link_record` = {$data1['id']} AND `record_caracter_id` = 1 order by {$_SESSION['id_base']} DESC";
				$Recordset2 = mysqli_query($connect, $query_Recordset2) or die(mysqli_error($connect));
				$row_Recordset2 = mysqli_fetch_assoc($Recordset2);
				$totalRows_Recordset2 = mysqli_num_rows($Recordset2);
				while($Recordset2 = mysqli_fetch_assoc($Recordset2)) {
					echo "Contato: ".$Recordset2["name"]."</br>";
					echo "CPF/CNPJ: ".$Recordset2["cpf_cnpj"]."</br>";
					echo "e-mail: ".$Recordset2["email"]."</br>";
					echo "Celular: ".$Recordset2["cellphone"]."</br>";
					echo "Telefone: ".$Recordset2["telephone"]."</br>";
					echo "Documento de identificação: ".$Recordset2["name"]."</br>";
					echo "</br>";
				}?>
				</td>
				<td bgcolor="#F5F5F5"><?php
				$_SESSION['DB_base'] = 'tupa';
				$_SESSION['table_base'] = 'projects_link_tpm';
				$query_Recordset3 = "SELECT * FROM {$_SESSION['table_base']} where people_record_id = {$row_Recordset1['id']} order by {$_SESSION['id_base']} DESC";
				$Recordset3 = mysqli_query($connect, $query_Recordset3) or die(mysqli_error($connect));
				$row_Recordset3 = mysqli_fetch_assoc($Recordset3);
				$totalRows_Recordset3 = mysqli_num_rows($Recordset3);
				while($data3 = mysqli_fetch_assoc($Recordset3)) {
					echo "Projeto: ".$Recordset3["id"]."</br>";
					echo "</br>";
				}?>
				</td>
				<td width="3%" bgcolor="#F5F5F5"><form
						action="mysql/update_process.php" method="POST">
						<input type="hidden" name="update_process"
							value="<?php echo $row_Recordset1[$_SESSION['id_base']] ?>"> <input
							type="image" name="submit" src="imagens/edit.png" width="24"
							height="24">
					</form></td>
				<td bgcolor="#F5F5F5"><form action="mysql/del_process.php"
						method="POST">
						<input type="hidden" name="delete_process"
							value="<?php echo $row_Recordset1[$_SESSION['id_base']] ?>"> <input
							type="hidden" name="delete_register"
							value="<?php echo $row_Recordset1['name'] ?>"> <input
							type="image" name="submit" src="imagens/delete.png" width="24"
							height="24">
					</form></td>
			</tr>
			<?php }?>
		</table>
	</fieldset>

	<div id="rec_openModal" class="modalDialog">
		<div>
			<a class="close" title="Fechar" href="#close">X</a>
			<fieldset>
				<legend>Realizar cadastro</legend>
				<br> <label>Modalidade:</label> <select name="modality"
					onChange="mostraDiv(this.value)">
					<option value="1">Cliente CPF</option>
					<option value="2">Cliente CNPJ</option>
					<option value="3">Contato de cliente</option>
					<option value="4">Endereço de cliente</option>
				</select> <br />
				<div id="cpf">
					<form action="mysql/insert_process.php" method="post" id='1'>
						<br> <label>Nome: </label> <input name='name' type='text' /><br />
						<br> <label>CPF: </label> <input name='cpf_cnpj' type='number'
							data-mask='000.000.000-00' /><br /> <br> <label>e-mail: </label>
						<input name='email' type='text' /><br /> <br> <label>Celular: </label>
						<input name='cellphone' type='text' data-mask="(00)0000-0000" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							data-mask='(00)00000-0000' autocomplete='off' /><br /> <br> <label>Documento
							de identificação: </label> <input type='file' name='doc_id'><br />
						<INPUT TYPE="hidden" NAME="record_caracter_id" VALUE="0"><INPUT
							TYPE="hidden" NAME="action" VALUE="0"> <br> <label><input
							type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="cnpj">
					<form action="mysql/insert_process.php" method="post" id='2'>
						<br> <label>Nome da empresa: </label> <input name='name'
							type='text' /><br /> <br> <label>CNPJ: </label> <input
							name='cpf_cnpj' type='text' data-mask="00.000.000/0000-00" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email' /><br />
						<br> <label>Celular: </label> <input name='cellphone' type='text'
							data-mask="00000-000" /><br /> <br> <label>Telefone: </label> <input
							name='telephone' type='text' /><br /> <br> <label>Documento de
							identificação: </label> <input name='doc_id' type='file' /><br />
						<INPUT TYPE="hidden" NAME="record_caracter_id" VALUE="0"><INPUT
							TYPE="hidden" NAME="action" VALUE="0"> <br> <label><input
							type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="contato">
					<form action="mysql/insert_process.php" method="post" id='3'>
						<br> <label>Nome: </label> <input name='name' type='text' /><br />
						<br> <label>cpf: </label> <input name='cpf' type='number'
							data-mask='000.000.000-00' /><br /> <br> <label>e-mail: </label>
						<input name='email' type='text' /><br /> <br> <label>Celular: </label>
						<input name='cellphone' type='text' data-mask="(00)0000-0000" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							data-mask='(00)00000-0000' autocomplete='off' /><br /> <br> <label>Documento
							de identificação: </label> <input type='file' name='doc_id'><br />
						<INPUT TYPE="hidden" NAME="record_caracter_id" VALUE="1"><br> <label>Contato
							do cliente </label> <select name="link_record">
							<?php
							while ($data = mysqli_fetch_array($Recordset1)) {
								echo("<option value='".$data['id']."'>".$data['name']."</option>");
							}
							?>
						</select><br /> <INPUT TYPE="hidden" NAME="action" VALUE="0"> <br>
						<label><input type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="endereco">
					<form action="mysql/insert_process.php" method="post" id='4'>
						<br> <label>CEP: </label> <input name='cep' type='text' /><br /> <br>
						<label>Logradouro: </label> <input name='address' type='text'
							data-mask="00000-000" autocomplete="off" /><br /> <br> <label>Número:
						</label> <input name='number' type='text' /><br /> <br> <label>Bairro:
						</label> <input name='neighborhood' type='text' /><br /> <br> <label>Cidade/UF:
						</label> <input name='city' type='text' /><input name='uf'
							type='text' /><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="4"><INPUT TYPE="hidden"
							NAME="action" VALUE="1"> <br> <label><input type="submit"
							value="Cadastrar" /> </label><br />
					</form>
				</div>
			</fieldset>
		</div>
	</div>
</body>
</html>
							<?php
							mysqli_free_result($Recordset1);
							mysqli_free_result($Recordset2);
							mysqli_free_result($Recordset3);
							?>

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Acredito que o erro seja na linha abaixo:

while($Recordset2 = mysqli_fetch_assoc($Recordset2)) {

Está usando a mesma variável para receber e passar o fetch_assoc, criar um $row para receber o fetch para testar.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não funcionou Marcos. Ainda está em loop infinito.

 

Trecho com while

<?php
				$_SESSION['DB_base'] = 'tupa';
				$_SESSION['table_base'] = 'people_records';
				$query_Recordset2 = "SELECT * FROM {$_SESSION['table_base']} WHERE `link_record` = {$row_1['id']} AND `record_caracter_id` = 1 order by {$_SESSION['id_base']} DESC";
				$Recordset2 = mysqli_query($connect, $query_Recordset2) or die(mysqli_error($connect));
				while($row_2 = mysqli_fetch_assoc($Recordset2)) {
					echo "Contato: ".$row_2["name"]."</br>";
					echo "CPF/CNPJ: ".$row_2["cpf_cnpj"]."</br>";
					echo "e-mail: ".$row_2["email"]."</br>";
					echo "Celular: ".$row_2["cellphone"]."</br>";
					echo "Telefone: ".$row_2["telephone"]."</br>";
					echo "Documento de identificação: ".$row_2["name"]."</br>";
					echo "</br>";
				}?>

 

 

 

Código inteiro:

<?php
session_start();
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];
$_SESSION['del_message'] = 'Deseja excluir o cliente ';
$_SESSION['DB_base'] = 'tupa';
$_SESSION['table_base'] = 'people_records';
$_SESSION['id_base'] = 'id';
require_once('connections.php');
$query_Recordset1 = "SELECT * FROM {$_SESSION['table_base']} WHERE record_caracter_id = '0' order by {$_SESSION['id_base']} DESC";
$Recordset1 = mysqli_query($connect, $query_Recordset1) or die(mysql_error());
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);
?>

<!doctype html>
<html lang='pt-br'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tupã - Serviços de Engenharia</title>

<link href='css/sistema.css' rel='stylesheet' type='text/css'
	media='all'>

<style type="text/css">
#cnpj {
	display: none;
}

#contato {
	display: none;
}

#endereco {
	display: none;
}

#projeto {
	display: none;
}
</style>
</head>
<body>
	<fieldset>
		<legend>Gerenciamento de Clientes</legend>
		<table id="tabela">
			<thead>
				<tr>
					<th>Descrição</th>
					<th>Contato</th>
					<th>Projetos</th>
					<th colspan="3">Ação</th>
				</tr>
				<tr>
					<th></th>
					<th></th>
					<th></th>
					<th colspan="3"><input type="submit" value="Filtrar" /> | <input
						type="button" onclick="javascript: location.href='#rec_openModal'"
						value="Adicionar" /></th>
				</tr>
			</thead>
			<?php while ($row_1 = $row_Recordset1){?>
			<tr>
				<td bgcolor="#F5F5F5"><p>
						Código:
						<?php echo $row_1['id']; ?>
						<br /> Cliente:
						<?php echo $row_1['name']; ?>
						<br /> CPF/CNPJ:
						<?php echo $row_1['cpf_cnpj']; ?>
						<br /> e-mail:
						<?php echo $row_1['email']; ?>
						<br /> Celular:
						<?php echo $row_1['cellphone']; ?>
						<br /> Telefone:
						<?php echo $row_1['telephone']; ?>
						<br /> Documento de identificação:
						<?php
						if(file_exists('imagens/clients/energy_bill/'.$row_1['id'].'.jpg'))
						{
							echo 'Documento de identificação: <a href=imagens/clients/energy_bill/'.$row_1['id'].'.jpg target="_blank"><img src="imagens/view.png" width="24" height="24">';
						}
						else
						{
							echo 'Documento de identificação: indisponível';
						}
						?>
					</p></td>
				<td bgcolor="#F5F5F5"><?php
				$_SESSION['DB_base'] = 'tupa';
				$_SESSION['table_base'] = 'people_records';
				$query_Recordset2 = "SELECT * FROM {$_SESSION['table_base']} WHERE `link_record` = {$row_1['id']} AND `record_caracter_id` = 1 order by {$_SESSION['id_base']} DESC";
				$Recordset2 = mysqli_query($connect, $query_Recordset2) or die(mysqli_error($connect));
				while($row_2 = mysqli_fetch_assoc($Recordset2)) {
					echo "Contato: ".$row_2["name"]."</br>";
					echo "CPF/CNPJ: ".$row_2["cpf_cnpj"]."</br>";
					echo "e-mail: ".$row_2["email"]."</br>";
					echo "Celular: ".$row_2["cellphone"]."</br>";
					echo "Telefone: ".$row_2["telephone"]."</br>";
					echo "Documento de identificação: ".$row_2["name"]."</br>";
					echo "</br>";
				}?>
				</td>
				<td bgcolor="#F5F5F5"><?php
				$_SESSION['DB_base'] = 'tupa';
				$_SESSION['table_base'] = 'projects_link_tpm';
				$query_Recordset3 = "SELECT * FROM {$_SESSION['table_base']} where people_record_id = {$row_Recordset1['id']} order by {$_SESSION['id_base']} DESC";
				$Recordset3 = mysqli_query($connect, $query_Recordset3) or die(mysqli_error($connect));
				while($row_3 = mysqli_fetch_assoc($Recordset3)) {
					echo "Projeto: ".$row_3["id"]."</br>";
					echo "</br>";
				}?>
				</td>
				<td width="3%" bgcolor="#F5F5F5"><form
						action="mysql/update_process.php" method="POST">
						<input type="hidden" name="update_process"
							value="<?php echo $row_1[$_SESSION['id_base']] ?>"> <input
							type="image" name="submit" src="imagens/edit.png" width="24"
							height="24">
					</form></td>
				<td bgcolor="#F5F5F5"><form action="mysql/del_process.php"
						method="POST">
						<input type="hidden" name="delete_process"
							value="<?php echo $row_1[$_SESSION['id_base']] ?>"> <input
							type="hidden" name="delete_register"
							value="<?php echo $row_1['name'] ?>"> <input
							type="image" name="submit" src="imagens/delete.png" width="24"
							height="24">
					</form></td>
			</tr>
			<?php }?>
		</table>
	</fieldset>

	<div id="rec_openModal" class="modalDialog">
		<div>
			<a class="close" title="Fechar" href="#close">X</a>
			<fieldset>
				<legend>Realizar cadastro</legend>
				<br> <label>Modalidade:</label> <select name="modality"
					onChange="mostraDiv(this.value)">
					<option value="1">Cliente CPF</option>
					<option value="2">Cliente CNPJ</option>
					<option value="3">Contato de cliente</option>
					<option value="4">Endereço de cliente</option>
				</select> <br />
				<div id="cpf">
					<form action="mysql/insert_process.php" method="post" id='1'>
						<br> <label>Nome: </label> <input name='name' type='text' /><br />
						<br> <label>CPF: </label> <input name='cpf_cnpj' type='number'
							placeholder="Ex.: 00000000000 (11 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email'
							placeholder="Ex.: seunome@dominio.com.br" /><br /> <br> <label>Celular:
						</label> <input name='cellphone' type='text'
							placeholder="Ex.: 0XX9YYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							placeholder="Ex.: 0XXYYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Documento de identificação: </label> <input
							type='file' name='doc_id'><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="0"><INPUT TYPE="hidden"
							NAME="action" VALUE="0"> <br> <label><input type="submit"
							value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="cnpj">
					<form action="mysql/insert_process.php" method="post" id='2'>
						<br> <label>Nome da empresa: </label> <input name='name'
							type='text' /><br /> <br> <label>CNPJ: </label> <input
							name='cpf_cnpj' type='number'
							placeholder="Ex.: 0000000000000 (14 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email'
							placeholder="Ex.: seunome@dominio.com.br" /><br /> <br> <label>Celular:
						</label> <input name='cellphone' type='text'
							placeholder="Ex.: 0XX9YYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							placeholder="Ex.: 0XXYYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Documento de identificação: </label> <input
							name='doc_id' type='file' /><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="0"><INPUT TYPE="hidden"
							NAME="action" VALUE="0"> <br> <label><input type="submit"
							value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="contato">
					<form action="mysql/insert_process.php" method="post" id='3'>
						<br> <label>Nome: </label> <input name='name' type='text' /><br />
						<br> <label>cpf: </label> <input name='cpf_cnpj' type='number'
							placeholder="Ex.: 00000000000 (11 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email'
							placeholder="Ex.: seunome@dominio.com.br" /><br /> <br> <label>Celular:
						</label> <input name='cellphone' type='text'
							placeholder="Ex.: 0XX9YYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							placeholder="Ex.: 0XXYYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Documento de identificação: </label> <input
							type='file' name='doc_id'><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="1"><br> <label>Contato do
							cliente </label> <select name="link_record">
							<?php
							while ($data = mysqli_fetch_array($Recordset1)) {
								echo("<option value='".$data['id']."'>".$data['name']."</option>");
							}
							?>
						</select><br /> <INPUT TYPE="hidden" NAME="action" VALUE="0"> <br>
						<label><input type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="endereco">
					<form action="mysql/insert_process.php" method="post" id='4'>
						<br> <label>CEP: </label> <input name='cep' type='number'
							placeholder="Ex.: 00000000 (8 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br /> <br>
						<label>Logradouro: </label> <input name='address' type='text' /><br />
						<br> <label>Número: </label> <input name='number' type='text' /><br />
						<br> <label>Bairro: </label> <input name='neighborhood'
							type='text' /><br /> <br> <label>Cidade/UF: </label> <input
							name='city' type='text' /><input name='uf' type='text' placeholder="Ex.: MG"
							pattern="[A-Z][A-Z]"/><br /> <INPUT
							TYPE="hidden" NAME="record_caracter_id" VALUE="4"><INPUT
							TYPE="hidden" NAME="action" VALUE="1"> <br> <label><input
							type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="projeto">
					<form action="mysql/insert_process.php" method="post">
						<br> <label>Produto:</label> <select name="name" id="name">
						<?php
						$_SESSION['DB_base'] = 'qdpm';
						$_SESSION['table_base'] = 'projects_types';
						$Recordset4 = mysqli_query($connect, "SELECT * FROM {$_SESSION['table_base']} order by {$_SESSION['id_base']} DESC") or die(mysql_error());
						while ($row_4 = mysqli_fetch_array($Recordset1)) {
							echo("<option value='".$row_4['name']."'>".$row_4['name']."</option>");
						}
						?>
						</select> <br /> <br> <label>Cliente:</label> <select
							name="client" id="client">
							<?php
							while ($row_5 = mysqli_fetch_array($Recordset1)) {
								echo("<option value='".$row_5['client']."'>".$row_5['client']."</option>");
							}
							?>
						</select> <br /> <input type="hidden" name="projects_status_id"
							value="1"> <input type="hidden" name="projects_type_id" value="2">
						<input type="hidden" name="created_by" value="3"> <input
							type="hidden" name="team" value="4,3,"> <label><input
							type="submit" value="Cadastrar" /> </label>
					</form>
				</div>
			</fieldset>
		</div>
	</div>
</body>
</html>
							<?php
							mysqli_free_result($Recordset1);
							mysqli_free_result($Recordset2);
							mysqli_free_result($Recordset3);
							?>

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

veja se a sua session de table_base traz algum valor... 

 

além disso, ja que você esta pondo as variaveis dentro dos colchetes, inclui aspas simples

 

coluna = '{$variavel}' 

 

mais ainda... se o table_base traz o nome da tabela corretamente, quantos registros existem nessa tabela?

 

as vezes o seu erro acontece pq você tem muitos registros para iterar e o servidor da crash/timeout assim como o navegador do usuario por ser muitos dados para imprimir...

 

afim de apenas teste implemente um limit 10 na sua query...

 

aplique a condicao mysqli_error apos a execucao da qiery para identificar possiveis erros

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom dia Luiz!

 

Existem 5 registros.

 

Ao adicionar as aspas, começou a retornar o seguinte erro:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''people_records' ORDER BY 'id' DESC' at line 1

Compartilhar este post


Link para o post
Compartilhar em outros sites

Os recordset estão retornando as pesquisas corretamente. Creio que o problema está nos while.

 

<?php
session_start();
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];
$_SESSION['del_message'] = 'Deseja excluir o cliente ';
require_once('connections.php');

$_SESSION['DB_base'] = 'tupa';
$_SESSION['table_base'] = 'people_records';
$_SESSION['id_base'] = 'id';
$query_Recordset1 = "SELECT * FROM {$_SESSION['table_base']} ORDER BY {$_SESSION['id_base']} DESC";
$Recordset1 = mysqli_query($connect, $query_Recordset1) or die(mysqli_error($connect));
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);

$_SESSION['table_base'] = 'projects_link_tpm';
$query_Recordset2 = "SELECT * FROM {$_SESSION['table_base']} ORDER BY {$_SESSION['id_base']} DESC";
$Recordset2 = mysqli_query($connect, $query_Recordset2) or die(mysqli_error($connect));
$row_Recordset2 = mysqli_fetch_assoc($Recordset2);
?>

<!doctype html>
<html lang='pt-br'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tupã - Serviços de Engenharia</title>

<link href='css/sistema.css' rel='stylesheet' type='text/css'
	media='all'>

<style type="text/css">
#cnpj {
	display: none;
}

#contato {
	display: none;
}

#endereco {
	display: none;
}

#projeto {
	display: none;
}
</style>
</head>
<body>
	<fieldset>
		<legend>Gerenciamento de Clientes</legend>
		<table id="tabela">
			<thead>
				<tr>
					<th>Descrição</th>
					<th>Contato</th>
					<th>Projetos</th>
					<th colspan="3">Ação</th>
				</tr>
				<tr>
					<th></th>
					<th></th>
					<th></th>
					<th colspan="3"><input type="submit" value="Filtrar" /> | <input
						type="button" onclick="javascript: location.href='#rec_openModal'"
						value="Adicionar" /></th>
				</tr>
			</thead>
			<?php while ($row_1 = $row_Recordset1){
				if ($row_1['record_caracter_id'] = '0') {
$row_1 = $row_Recordset1;
					?>
			<tr>
				<td bgcolor="#F5F5F5"><p>
				<?php
				echo "Cliente: ".$row_1["name"]."</br>";
				echo "CPF/CNPJ: ".$row_1["cpf_cnpj"]."</br>";
				echo "e-mail: ".$row_1["email"]."</br>";
				echo "Celular: ".$row_1["cellphone"]."</br>";
				echo "Telefone: ".$row_1["telephone"]."</br>";
				if(file_exists('imagens/clients/energy_bill/'.$row_1['id'].'.jpg'))
				{
					echo 'Documento de identificação: <a href=imagens/clients/energy_bill/'.$row_1['id'].'.jpg target="_blank"><img src="imagens/view.png" width="24" height="24">';
				}
				else
				{
					echo 'Documento de identificação: indisponível';
				}
				?>
					</p>
				</td>
				<td bgcolor="#F5F5F5"><?php
				while($row_2 = $row_Recordset1) {
					if ($row_2['link_record'] = $row_1['id'] AND $row_2['record_caracter_id'] = '1') {
						echo "Contato: ".$row_2["name"]."</br>";
						echo "CPF/CNPJ: ".$row_2["cpf_cnpj"]."</br>";
						echo "e-mail: ".$row_2["email"]."</br>";
						echo "Celular: ".$row_2["cellphone"]."</br>";
						echo "Telefone: ".$row_2["telephone"]."</br>";
						echo "Documento de identificação: ".$row_2["name"]."</br>";
						echo "</br>";
					}}?>
				</td>
				<td bgcolor="#F5F5F5"><?php
				while($row_3 = $row_Recordset2) {
					if ($row_3['people_record_id'] = $row_1['id']) {
						echo "Projeto: ".$row_3["id"]."</br>";
						echo "</br>";
					}}?></td>
				<td width="3%" bgcolor="#F5F5F5"><form
						action="mysql/update_process.php" method="POST">
						<input type="hidden" name="update_process"
							value="<?php echo $row_1[$_SESSION['id_base']] ?>"> <input
							type="image" name="submit" src="imagens/edit.png" width="24"
							height="24">
					</form></td>
				<td bgcolor="#F5F5F5"><form action="mysql/del_process.php"
						method="POST">
						<input type="hidden" name="delete_process"
							value="<?php echo $row_1[$_SESSION['id_base']] ?>"> <input
							type="hidden" name="delete_register"
							value="<?php echo $row_1['name'] ?>"> <input type="image"
							name="submit" src="imagens/delete.png" width="24" height="24">
					</form></td>
			</tr>
			<?php }}?>
		</table>
	</fieldset>

	<div id="rec_openModal" class="modalDialog">
		<div>
			<a class="close" title="Fechar" href="#close">X</a>
			<fieldset>
				<legend>Realizar cadastro</legend>
				<br> <label>Modalidade:</label> <select name="modality"
					onChange="mostraDiv(this.value)">
					<option value="1">Cliente CPF</option>
					<option value="2">Cliente CNPJ</option>
					<option value="3">Contato de cliente</option>
					<option value="4">Endereço de cliente</option>
				</select> <br />
				<div id="cpf">
					<form action="mysql/insert_process.php" method="post" id='1'>
						<br> <label>Nome: </label> <input name='name' type='text' /><br />
						<br> <label>CPF: </label> <input name='cpf_cnpj' type='number'
							placeholder="Ex.: 00000000000 (11 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email'
							placeholder="Ex.: seunome@dominio.com.br" /><br /> <br> <label>Celular:
						</label> <input name='cellphone' type='text'
							placeholder="Ex.: 0XX9YYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							placeholder="Ex.: 0XXYYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Documento de identificação: </label> <input
							type='file' name='doc_id'><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="0"><INPUT TYPE="hidden"
							NAME="action" VALUE="0"> <br> <label><input type="submit"
							value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="cnpj">
					<form action="mysql/insert_process.php" method="post" id='2'>
						<br> <label>Nome da empresa: </label> <input name='name'
							type='text' /><br /> <br> <label>CNPJ: </label> <input
							name='cpf_cnpj' type='number'
							placeholder="Ex.: 0000000000000 (14 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email'
							placeholder="Ex.: seunome@dominio.com.br" /><br /> <br> <label>Celular:
						</label> <input name='cellphone' type='text'
							placeholder="Ex.: 0XX9YYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							placeholder="Ex.: 0XXYYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Documento de identificação: </label> <input
							name='doc_id' type='file' /><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="0"><INPUT TYPE="hidden"
							NAME="action" VALUE="0"> <br> <label><input type="submit"
							value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="contato">
					<form action="mysql/insert_process.php" method="post" id='3'>
						<br> <label>Nome: </label> <input name='name' type='text' /><br />
						<br> <label>cpf: </label> <input name='cpf_cnpj' type='number'
							placeholder="Ex.: 00000000000 (11 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email'
							placeholder="Ex.: seunome@dominio.com.br" /><br /> <br> <label>Celular:
						</label> <input name='cellphone' type='text'
							placeholder="Ex.: 0XX9YYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							placeholder="Ex.: 0XXYYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Documento de identificação: </label> <input
							type='file' name='doc_id'><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="1"><br> <label>Contato do
							cliente </label> <select name="link_record">
							<?php
							while ($row_4 = mysqli_fetch_array($Recordset1)) {
								echo("<option value='".$row_4['id']."'>".$row_4['name']."</option>");
							}
							?>
						</select><br /> <INPUT TYPE="hidden" NAME="action" VALUE="0"> <br>
						<label><input type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="endereco">
					<form action="mysql/insert_process.php" method="post" id='4'>
						<br> <label>CEP: </label> <input name='cep' type='number'
							placeholder="Ex.: 00000000 (8 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br /> <br>
						<label>Logradouro: </label> <input name='address' type='text' /><br />
						<br> <label>Número: </label> <input name='number' type='text' /><br />
						<br> <label>Bairro: </label> <input name='neighborhood'
							type='text' /><br /> <br> <label>Cidade/UF: </label> <input
							name='city' type='text' /><input name='uf' type='text'
							placeholder="Ex.: MG" pattern="[A-Z][A-Z]" /><br /> <INPUT
							TYPE="hidden" NAME="record_caracter_id" VALUE="4"><INPUT
							TYPE="hidden" NAME="action" VALUE="1"> <br> <label><input
							type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="projeto">
					<form action="mysql/insert_process.php" method="post">
						<br> <label>Produto:</label> <select name="name" id="name">
						<?php
						$_SESSION['DB_base'] = 'qdpm';
						$_SESSION['table_base'] = 'projects_types';
						$Recordset5 = mysqli_query($connect, "SELECT * FROM {$_SESSION['table_base']} order by {$_SESSION['id_base']} DESC") or die(mysql_error());
						while ($row_5 = mysqli_fetch_array($Recordset1)) {
							echo("<option value='".$row_5['name']."'>".$row_5['name']."</option>");
						}
						?>
						</select> <br /> <br> <label>Cliente:</label> <select
							name="client" id="client">
							<?php
							while ($row_5 = mysqli_fetch_array($Recordset1)) {
								echo("<option value='".$row_5['client']."'>".$row_5['client']."</option>");
							}
							?>
						</select> <br /> <input type="hidden" name="projects_status_id"
							value="1"> <input type="hidden" name="projects_type_id" value="2">
						<input type="hidden" name="created_by" value="3"> <input
							type="hidden" name="team" value="4,3,"> <label><input
							type="submit" value="Cadastrar" /> </label>
					</form>
				</div>
			</fieldset>
		</div>
	</div>
</body>
</html>
							<?php
							mysqli_free_result($Recordset1);
							mysqli_free_result($Recordset2);
							mysqli_free_result($Recordset3);
							?>

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Depois de muito mexer, está dando erro fatal na linha 64 (linha do if)

 

			<?php while ($row_1 = $row_Recordset1) {
				if ($row_1['record_caracter_id'] == '0') {
					?>
			<tr>

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tente por favor: 

<?php
session_start();
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];
$_SESSION['del_message'] = 'Deseja excluir o cliente ';
$_SESSION['DB_base'] = 'tupa';
$_SESSION['table_base'] = 'people_records';
$_SESSION['id_base'] = 'id';
require_once('connections.php');
$query_Recordset1 = "SELECT * FROM {$_SESSION['table_base']} WHERE record_caracter_id = '0' order by {$_SESSION['id_base']} DESC";
$Recordset1 = mysqli_query($connect, $query_Recordset1) or die(mysql_error());
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);
?>

<!doctype html>
<html lang='pt-br'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tupã - Serviços de Engenharia</title>

<link href='css/sistema.css' rel='stylesheet' type='text/css'
	media='all'>

<style type="text/css">
#cnpj {
	display: none;
}

#contato {
	display: none;
}

#endereco {
	display: none;
}
</style>
</head>
<body>
	<fieldset>
		<legend>Gerenciamento de Clientes</legend>
		<table id="tabela">
			<thead>
				<tr>
					<th>Descrição</th>
					<th>Contato</th>
					<th>Projetos</th>
					<th colspan="3">Ação</th>
				</tr>
				<tr>
					<th></th>
					<th></th>
					<th></th>
					<th colspan="3"><input type="submit" value="Filtrar" /> | <input
						type="button" onclick="javascript: location.href='#rec_openModal'"
						value="Adicionar" /></th>
				</tr>
			</thead>
			<?php while ($new_cordset1 = mysqli_fetch_assoc($Recordset1)){?>
			<tr>
				<td bgcolor="#F5F5F5"><p>
						Código:
						<?php echo $new_cordset1['id']; ?>
						<br /> Cliente:
						<?php echo $new_cordset1['name']; ?>
						<br /> CPF/CNPJ:
						<?php echo $new_cordset1['cpf_cnpj']; ?>
						<br /> e-mail:
						<?php echo $new_cordset1['email']; ?>
						<br /> Celular:
						<?php echo $new_cordset1['cellphone']; ?>
						<br /> Telefone:
						<?php echo $new_cordset1['telephone']; ?>
						<br /> Documento de identificação:
						<?php
						if(file_exists('imagens/clients/energy_bill/'.$new_cordset1['id'].'.jpg'))
						{
							echo 'Documento de identificação: <a href=imagens/clients/energy_bill/'.$new_cordset1['id'].'.jpg target="_blank"><img src="imagens/view.png" width="24" height="24">';
						}
						else
						{
							echo 'Documento de identificação: indisponível';
						}
						?>
					</p></td>
				<td bgcolor="#F5F5F5"><?php
				$_SESSION['DB_base'] = 'tupa';
				$_SESSION['table_base'] = 'people_records';
				$query_Recordset2 = "SELECT * FROM {$_SESSION['table_base']} WHERE `link_record` = {$data1['id']} AND `record_caracter_id` = 1 order by {$_SESSION['id_base']} DESC";
				$Recordset2 = mysqli_query($connect, $query_Recordset2) or die(mysqli_error($connect));
				$row_Recordset2 = mysqli_fetch_assoc($Recordset2);
				$totalRows_Recordset2 = mysqli_num_rows($Recordset2);
				while($new_cordset2 = mysqli_fetch_assoc($Recordset2)) {
					echo "Contato: ".$new_cordset2["name"]."</br>";
					echo "CPF/CNPJ: ".$new_cordset2["cpf_cnpj"]."</br>";
					echo "e-mail: ".$new_cordset2["email"]."</br>";
					echo "Celular: ".$new_cordset2["cellphone"]."</br>";
					echo "Telefone: ".$new_cordset2["telephone"]."</br>";
					echo "Documento de identificação: ".$new_cordset2["name"]."</br>";
					echo "</br>";
				}?>
				</td>
				<td bgcolor="#F5F5F5"><?php
				$_SESSION['DB_base'] = 'tupa';
				$_SESSION['table_base'] = 'projects_link_tpm';
				$query_Recordset3 = "SELECT * FROM {$_SESSION['table_base']} where people_record_id = {$row_Recordset1['id']} order by {$_SESSION['id_base']} DESC";
				$Recordset3 = mysqli_query($connect, $query_Recordset3) or die(mysqli_error($connect));
				$row_Recordset3 = mysqli_fetch_assoc($Recordset3);
				$totalRows_Recordset3 = mysqli_num_rows($Recordset3);
				while($new_cordset3 = mysqli_fetch_assoc($Recordset3)) {
					echo "Projeto: ".$new_cordset3["id"]."</br>";
					echo "</br>";
				}?>
				</td>
				<td width="3%" bgcolor="#F5F5F5"><form
						action="mysql/update_process.php" method="POST">
						<input type="hidden" name="update_process"
							value="<?php echo $row_Recordset1[$_SESSION['id_base']] ?>"> <input
							type="image" name="submit" src="imagens/edit.png" width="24"
							height="24">
					</form></td>
				<td bgcolor="#F5F5F5"><form action="mysql/del_process.php"
						method="POST">
						<input type="hidden" name="delete_process"
							value="<?php echo $row_Recordset1[$_SESSION['id_base']] ?>"> <input
							type="hidden" name="delete_register"
							value="<?php echo $row_Recordset1['name'] ?>"> <input
							type="image" name="submit" src="imagens/delete.png" width="24"
							height="24">
					</form></td>
			</tr>
			<?php }?>
		</table>
	</fieldset>

	<div id="rec_openModal" class="modalDialog">
		<div>
			<a class="close" title="Fechar" href="#close">X</a>
			<fieldset>
				<legend>Realizar cadastro</legend>
				<br> <label>Modalidade:</label> <select name="modality"
					onChange="mostraDiv(this.value)">
					<option value="1">Cliente CPF</option>
					<option value="2">Cliente CNPJ</option>
					<option value="3">Contato de cliente</option>
					<option value="4">Endereço de cliente</option>
				</select> <br />
				<div id="cpf">
					<form action="mysql/insert_process.php" method="post" id='1'>
						<br> <label>Nome: </label> <input name='name' type='text' /><br />
						<br> <label>CPF: </label> <input name='cpf_cnpj' type='number'
							data-mask='000.000.000-00' /><br /> <br> <label>e-mail: </label>
						<input name='email' type='text' /><br /> <br> <label>Celular: </label>
						<input name='cellphone' type='text' data-mask="(00)0000-0000" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							data-mask='(00)00000-0000' autocomplete='off' /><br /> <br> <label>Documento
							de identificação: </label> <input type='file' name='doc_id'><br />
						<INPUT TYPE="hidden" NAME="record_caracter_id" VALUE="0"><INPUT
							TYPE="hidden" NAME="action" VALUE="0"> <br> <label><input
							type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="cnpj">
					<form action="mysql/insert_process.php" method="post" id='2'>
						<br> <label>Nome da empresa: </label> <input name='name'
							type='text' /><br /> <br> <label>CNPJ: </label> <input
							name='cpf_cnpj' type='text' data-mask="00.000.000/0000-00" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email' /><br />
						<br> <label>Celular: </label> <input name='cellphone' type='text'
							data-mask="00000-000" /><br /> <br> <label>Telefone: </label> <input
							name='telephone' type='text' /><br /> <br> <label>Documento de
							identificação: </label> <input name='doc_id' type='file' /><br />
						<INPUT TYPE="hidden" NAME="record_caracter_id" VALUE="0"><INPUT
							TYPE="hidden" NAME="action" VALUE="0"> <br> <label><input
							type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="contato">
					<form action="mysql/insert_process.php" method="post" id='3'>
						<br> <label>Nome: </label> <input name='name' type='text' /><br />
						<br> <label>cpf: </label> <input name='cpf' type='number'
							data-mask='000.000.000-00' /><br /> <br> <label>e-mail: </label>
						<input name='email' type='text' /><br /> <br> <label>Celular: </label>
						<input name='cellphone' type='text' data-mask="(00)0000-0000" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							data-mask='(00)00000-0000' autocomplete='off' /><br /> <br> <label>Documento
							de identificação: </label> <input type='file' name='doc_id'><br />
						<INPUT TYPE="hidden" NAME="record_caracter_id" VALUE="1"><br> <label>Contato
							do cliente </label> <select name="link_record">
							<?php
							while ($new_cordset4 = mysqli_fetch_array($Recordset1)) {
								echo("<option value='".$new_cordset4['id']."'>".$new_cordset4['name']."</option>");
							}
							?>
						</select><br /> <INPUT TYPE="hidden" NAME="action" VALUE="0"> <br>
						<label><input type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="endereco">
					<form action="mysql/insert_process.php" method="post" id='4'>
						<br> <label>CEP: </label> <input name='cep' type='text' /><br /> <br>
						<label>Logradouro: </label> <input name='address' type='text'
							data-mask="00000-000" autocomplete="off" /><br /> <br> <label>Número:
						</label> <input name='number' type='text' /><br /> <br> <label>Bairro:
						</label> <input name='neighborhood' type='text' /><br /> <br> <label>Cidade/UF:
						</label> <input name='city' type='text' /><input name='uf'
							type='text' /><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="4"><INPUT TYPE="hidden"
							NAME="action" VALUE="1"> <br> <label><input type="submit"
							value="Cadastrar" /> </label><br />
					</form>
				</div>
			</fieldset>
		</div>
	</div>
</body>
</html>
							<?php
							mysqli_free_result($Recordset1);
							mysqli_free_result($Recordset2);
							mysqli_free_result($Recordset3);
							?>

Espero ter Ajudado :)

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ajudou! Mas o correto é ter uma pesquisa separado para cada while também. Resolvido!

Vou postar o código final.

 

<?php
session_start();
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];
$_SESSION['del_message'] = 'Deseja excluir o cliente ';
require_once('phpfunctions.php');

$Recordset1 = mysqli_query(connect(tupa), "SELECT * FROM people_records WHERE record_caracter_id = 0 ORDER BY id DESC") or die(mysqli_error(connect(tupa)));
?>

<!doctype html>
<html lang='pt-br'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tupã - Serviços de Engenharia</title>

<link href='css/sistema.css' rel='stylesheet' type='text/css'
	media='all'>

<style type="text/css">
#cnpj {
	display: none;
}

#contato {
	display: none;
}

#endereco {
	display: none;
}

#projeto {
	display: none;
}
</style>
</head>
<body>
	<fieldset>
		<legend>Gerenciamento de Clientes</legend>
		<table id="tabela">
			<thead>
				<tr>
					<th>Descrição</th>
					<th>Contato</th>
					<th>Projetos</th>
					<th colspan="3">Ação</th>
				</tr>
				<tr>
					<th></th>
					<th></th>
					<th></th>
					<th colspan="3"><input type="submit" value="Filtrar" /> | <input
						type="button" onclick="javascript: location.href='#rec_openModal'"
						value="Adicionar" /></th>
				</tr>
			</thead>
			<?php while ($row_1 = mysqli_fetch_assoc($Recordset1)) {
				?>
			<tr>
				<td bgcolor="#F5F5F5"><p>
				<?php
				echo "Cliente: ".$row_1["name"]."</br>";
				echo "CPF/CNPJ: ".$row_1["cpf_cnpj"]."</br>";
				echo "e-mail: ".$row_1["email"]."</br>";
				echo "Celular: ".$row_1["cellphone"]."</br>";
				echo "Telefone: ".$row_1["telephone"]."</br>";
				if(file_exists('imagens/clients/energy_bill/'.$row_1['id'].'.jpg'))
				{
					echo 'Documento de identificação: <a href=imagens/clients/energy_bill/'.$row_1['id'].'.jpg target="_blank"><img src="imagens/view.png" width="24" height="24">';
				}
				else
				{
					echo 'Documento de identificação: indisponível';
				}
				?>
					</p>
				</td>
				<td bgcolor="#F5F5F5"><?php
				$Recordset2 = mysqli_query(connect(tupa), "SELECT * FROM people_records WHERE record_caracter_id = 1 AND link_record = {$row_1['id']} ORDER BY id DESC") or die(mysqli_error(connect(tupa)));
				while($row_2 = mysqli_fetch_assoc($Recordset2)) {
					if ($row_2['link_record'] = $row_1['id'] AND $row_2['record_caracter_id'] = '1') {
						echo "Contato: ".$row_2["name"]."</br>";
						echo "CPF/CNPJ: ".$row_2["cpf_cnpj"]."</br>";
						echo "e-mail: ".$row_2["email"]."</br>";
						echo "Celular: ".$row_2["cellphone"]."</br>";
						echo "Telefone: ".$row_2["telephone"]."</br>";
						echo "Documento de identificação: ".$row_2["name"]."</br>";
						echo "</br>";
					}}?>
				</td>
				<td bgcolor="#F5F5F5"><?php
				$query_Recordset3 = "SELECT * FROM projects_link_tpm WHERE people_record_id = {$row_1['id']} ORDER BY id DESC";
				$Recordset3 = mysqli_query(connect(tupa), $query_Recordset3) or die(mysqli_error(connect(tupa)));
				$row_Recordset3 = mysqli_fetch_assoc($Recordset3);
				while($row_3 = mysqli_fetch_assoc($Recordset3)) {
					echo "Projeto: ".$row_3["id"]."</br>";
					echo "</br>";
				}?>
				</td>
				<td width="3%" bgcolor="#F5F5F5"><form
						action="mysql/update_process.php" method="POST">
						<input type="hidden" name="update_process"
							value="<?php echo $row_1['id'] ?>"> <input type="image"
							name="submit" src="imagens/edit.png" width="24" height="24">
					</form></td>
				<td bgcolor="#F5F5F5"><form action="mysql/del_process.php"
						method="POST">
						<input type="hidden" name="delete_process"
							value="<?php echo $row_1['id'] ?>"> <input type="hidden"
							name="delete_register" value="<?php echo $row_1['name'] ?>"> <input
							type="image" name="submit" src="imagens/delete.png" width="24"
							height="24">
					</form></td>
			</tr>
			<?php }?>
		</table>
	</fieldset>
	<div id="rec_openModal" class="modalDialog">
		<div>
			<a class="close" title="Fechar" href="#close">X</a>
			<fieldset>
				<legend>Realizar cadastro</legend>
				<br> <label>Cadastrar </label> <select name="modality"
					onChange="mostraDiv(this.value)">
					<option value="1">novo cliente CPF</option>
					<option value="2">novo cliente CNPJ</option>
					<option value="3">novo contato de cliente</option>
					<option value="4">novo endereço de cliente ou contato</option>
					<option value="5">novo projeto</option>
				</select> <br />
				<div id="cpf">
					<form action="mysql/insert_process.php" method="post" id='1'>
						<br> <label>Nome: </label> <input name='name' type='text' /><br />
						<br> <label>CPF: </label> <input name='cpf_cnpj' type='number'
							placeholder="Ex.: 00000000000 (11 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email'
							placeholder="Ex.: seunome@dominio.com.br" /><br /> <br> <label>Celular:
						</label> <input name='cellphone' type='text'
							placeholder="Ex.: 0XX9YYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							placeholder="Ex.: 0XXYYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Documento de identificação: </label> <input
							type='file' name='doc_id'><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="0"><INPUT TYPE="hidden"
							NAME="action" VALUE="0"> <br> <label><input type="submit"
							value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="cnpj">
					<form action="mysql/insert_process.php" method="post" id='2'>
						<br> <label>Nome da empresa: </label> <input name='name'
							type='text' /><br /> <br> <label>CNPJ: </label> <input
							name='cpf_cnpj' type='number'
							placeholder="Ex.: 0000000000000 (14 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email'
							placeholder="Ex.: seunome@dominio.com.br" /><br /> <br> <label>Celular:
						</label> <input name='cellphone' type='text'
							placeholder="Ex.: 0XX9YYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							placeholder="Ex.: 0XXYYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Documento de identificação: </label> <input
							name='doc_id' type='file' /><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="0"><INPUT TYPE="hidden"
							NAME="action" VALUE="0"> <br> <label><input type="submit"
							value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="contato">
					<form action="mysql/insert_process.php" method="post" id='3'>
						<br> <label>Nome: </label> <input name='name' type='text' /><br />
						<br> <label>cpf: </label> <input name='cpf_cnpj' type='number'
							placeholder="Ex.: 00000000000 (11 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>e-mail: </label> <input name='email' type='email'
							placeholder="Ex.: seunome@dominio.com.br" /><br /> <br> <label>Celular:
						</label> <input name='cellphone' type='text'
							placeholder="Ex.: 0XX9YYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Telefone: </label> <input name='telephone' type='text'
							placeholder="Ex.: 0XXYYYYYYYY"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br />
						<br> <label>Documento de identificação: </label> <input
							type='file' name='doc_id'><br /> <INPUT TYPE="hidden"
							NAME="record_caracter_id" VALUE="1"><br> <label>Contato do
							cliente </label> <select name="link_record">
							<?php
							while ($row_4 = mysqli_fetch_array($Recordset1)) {
								echo("<option value='".$row_4['id']."'>".$row_4['name']."</option>");
							}
							?>
						</select><br /> <INPUT TYPE="hidden" NAME="action" VALUE="0"> <br>
						<label><input type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="endereco">
					<form action="mysql/insert_process.php" method="post" id='4'>
						<br> <label>CEP: </label> <input name='cep' type='number'
							placeholder="Ex.: 00000000 (8 números)"
							pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" /><br /> <br>
						<label>Logradouro: </label> <input name='address' type='text' /><br />
						<br> <label>Número: </label> <input name='number' type='text' /><br />
						<br> <label>Bairro: </label> <input name='neighborhood'
							type='text' /><br /> <br> <label>Cidade/UF: </label> <input
							name='city' type='text' /><input name='uf' type='text'
							placeholder="Ex.: MG" pattern="[A-Z][A-Z]" /><br /> <INPUT
							TYPE="hidden" NAME="record_caracter_id" VALUE="4"><INPUT
							TYPE="hidden" NAME="action" VALUE="1"> <br> <label><input
							type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
				<div id="projeto">
					<form action="mysql/insert_process.php" method="post">
						<br> <label>Produto:</label> <select name="name" id="name">
						<?php
						$Recordset5 = mysqli_query(connect(qdpm), "SELECT * FROM projects_types ORDER BY id ASC") or die(mysql_error());
						while ($row_5 = mysqli_fetch_array($Recordset5)) {
							echo("<option value='".$row_5['name']."'>".$row_5['name']."</option>");
						}
						?>
						</select> <br /> <br> <label>Cliente:</label> <select
							name="client" id="client">
							<?php
							$Recordset6 = mysqli_query(connect(tupa), "SELECT * FROM people_records WHERE record_caracter_id = 0 ORDER BY id DESC") or die(mysql_error());
							while ($row_6 = mysqli_fetch_array($Recordset6)) {
								echo("<option value='".$row_6['id']."'>".$row_6['name']."</option>");
							}
							?>
						</select> <br /> <input type="hidden" name="projects_status_id"
							value="1"> <input type="hidden" name="projects_type_id" value="2">
						<input type="hidden" name="created_by" value="3"> <input
							type="hidden" name="team" value="4,3,"> <br> <label><input
							type="submit" value="Cadastrar" /> </label><br />
					</form>
				</div>
			</fieldset>
		</div>
	</div>
</body>
</html>
							<?php
							mysqli_free_result($Recordset1);
							mysqli_free_result($Recordset2);
							mysqli_free_result($Recordset3);
							?>

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

  • Conteúdo Similar

    • Por landerbadi
      Olá pessoal, boa tarde
       
      Tenho uma tabela chamada "produtos" com os seguintes campos (id, produto) e outra tabela chamada "itens" com os seguintes campos (id, prod_01, prod_02, prod_03, prod_04).
       
      Na tabela produtos eu tenho cadastrado os seguintes produtos: laranja, maçã, uva, goiaba, arroz, feijão, macarrão, etc.
       
      Na tabela itens eu tenho cadastrado os itens da seguinte maneira:
       
      1, laranja, uva, arroz, feijão;
      2, maçã, macarrão, goiaba, uva;
      3, arroz, feijão, maçã, azeite
       
      Meu problema é o seguinte: 
      Eu escolho um produto da tabela "produtos", por exemplo "uva".  Preciso fazer uma consulta na tabela "itens" para ser listado todos os registros que contenham o produto "uva" e que todos os demais produtos estejam cadastrados na tabela "produtos".
       
      No exemplo acima seria listado apenas dois registros, pois o terceiro registro não contém o produto "uva". 
       
      Alguém pode me ajudar? Pois estou quebrando a cabeça a vários dias e não consigo achar uma solução.
    • Por landerbadi
      Boa tarde pessoal. Estou tentado fazer uma consulta no banco de dados porém estou tendo dificuldades. Tenho uma tabela chamada "itens" com os seguintes campos: id, item, plural, ativo. Nela tem cadastrado vários itens e seu respectivo plural. No campo ativo eu coloco a letra "S" para informar que esta palavra está ativa no sistema. Por exemplo: 1, casa, casas, S 2, mesa, mesas, S 3, cama, camas, S 4, moto, motos, S 5, rádio, rádios O quinto registro "radio" não está ativo no sistema pois não tem um "S" no campo ativo. E outra tabela chamada "variações" com os seguintes campos (id, item1, item2, item3) com os seguintes registros: 1, casa, camas, moto 2, mesas, casas, radio 3, rádio, cama, mesa Eu preciso fazer uma busca na tabela variações da seguinte maneira: Eu escolho um registro na tabela "itens", por exemplo "casa". Preciso fazer com que o php me liste todos os registros da tabela "variações" que contenham a palavra "casa". Porém se tiver algum registro com a palavra "casas" também tem que ser listado. Neste caso ele irá encontrar dois registros. Agora eu preciso que o php verifique os demais itens e faça a listagem apenas dos item que estão ativos (que contenham um "S" no campo ativo. Neste caso ele irá encontrar apenas um registro, pois o segundo registro contém a palavra "rádio". E "rádio" não está ativo na tabela itens. Como faço isso?
    • Por ILR master
      Fala pessoal.
       
      Seguinte:
       
      Quero selecionar duas tabelas e mostrar com resultados intercalados. Abaixo segue um código explicando para vcs terem uma ideia.
       
      $consulta = "SELECT A.*, B.* FROM tabela1 A, tabela2 B'";
      $resultado = mysqli_query($conexao, $consulta) or die ("erro");
      while($busca = mysqli_fetch_array($resultado)){
       
      print $busca['cod_evento']; --> traz o código da tabela1 
      print $busca['titulo_evento']; -->  traz o titulo da tabela1
      print $busca['cod_noticia']; --> traz o código da tabela2
      print $busca['titulo_noticia']; --> traz o tituloda tabela2
       
      }
       
      Espero que entendam. Grato
       
    • Por gersonab
      Bom dia
      estou com uma dúvida de como proceder, tenho uma tabela de categoria e uma de subcategoria, a categoria pode ter várias subs, até ai tranquilo, quando faço update de uma sub altero normalmente a quantidade deste, até aí normal, porém me deparei com uma situação um pouco diferente, vou tentar ser o mais claro possível, de certa forma algumas subs são comuns só mudando o nome praticamente, aí eu preciso que ao efetuar o update em umas destas este ocorra nas demais, tipo:
       
      Se o id da sub for 5 , eu preciso fazer o mesmo update nos ids 6 e 7 ;
       
      Se o id da sub for 9 , eu preciso fazer o mesmo update no id 10
       
      se for 2 , fazer o update somente neste
       
      ainda não estou conseguindo ver uma lógica para isso, e ou uma nova coluna para cadastrar em comum nestes casos.
       
      qual seria a melhor opção
    • Por babylon
      Olá galera tudo bem?
      Deixa eu perguntar, estava mexendo no meu site e queria adicionar em html essa tabela porem esta dando erro pois fica assim:
       

      Porem gostaria que ficasse assim:

      Segue o código da tabela:
      <center><table border="0">
          <tr>
      <td bgcolor="#0092df" width="24%"><a href="/categorias?ename=smartphones"><span style="font-size: 20px; color: #ffffff;"><b> <font color="#0092df">..</font>Bicicleta<br> <font color="#0092df">..</font>Track Bikes<br> <font color="#0092df">..</font>Aro 29 TKS</b></a></span><br><br><font size="5"><center><span style="background-color: #A1CD44">DE:</span></font> <br><font size="5"><s>R$ 1.999,99</center></font></s> </td><td><p><a href="/categorias?ename=smartphones"><img src="/static/img/itembicicleta.jpg"><br><font size="5"><center><span style="background-color: #A1CD44">COM - 60%:</span></font> <br><font size="5">1.199,99</font></center></a></td>
             <td><font color="#ffffff">....</font></td>
              <td bgcolor="#0092df" width="24%"><a href="/categorias?ename=smartphones"><span style="font-size: 20px; color: #ffffff;"><b> <font color="#0092df">..</font>Monitor 24"<br> <font color="#0092df">..</font>Samsung<font color="#0092df">aa.aa</font><br> <font color="#0092df">..</font>1ms 144hz</b></a></span></center></td><td><p><a href="/categorias?ename=smartphones"><img src="/static/img/itemmonitor.jpg"></a></td>
          </tr>
          </table></center>
      O que estaria errado, pois não sei como colocar nessa tabela outro fundo de outra cor, veja que usei td bgcolor="#0092df" para o azul escuro mas não sei como usaria pro "#e4f1fb" para o fundo ficar de azul claro em baixo bem como não ficou correto em altura o "DE:" com o "COM - 60%:".
      Bom é isso, obg.


×

Informação importante

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