Field of research and pagination

Asked

Viewed 32 times

0

I have as objective the realization of a field of research, as also the pagination, both worked until I realized a popup that was intended to present the data of each client that were inserted in other tables, through the realization of JOINS I was able to accomplish such task, but since then when performing a search no changes are made, presents that there is more than one page but however when I click on the second page it presents exactly the same as the first and the data can be entered successfully but however are not presented , however whenever I delete the JOIN performed everything goes back to normal.

    
<?php header('Content-type: text/plain; charset=utf-8'); ?>
<?php
	if (isset($_REQUEST['pesquisa']) && $_REQUEST['pesquisa']!='') {
		$pesq1=$_REQUEST['pesquisa']; 
		$pesq=$_REQUEST['pesquisa']; 
		$pesq='%'.$pesq1.'%';
	}else 
		$pesq='';
	
	$tp=10;
	if (isset($_REQUEST['pag'])) $np=$_REQUEST['pag']; else $np=1;
	
	$ini=($np-1)*$tp; //registo inicial a ser mostrado
	$sql="select * from Terceiros where  1=1";	
	if ($pesq !='') 
		$sql.=" and upper(Numero) like upper('$pesq')";
	$sql.=" order by Numero";
	$res=$lig->query($sql);
	$nr=$res->num_rows;
	$qp=$nr/$tp+1;
	mysql_free_result($res);
	?>
	 
	<form align="center" method="POST" action="index.php?cmd=lister">
		Pesquisar Terceiros: <input type="text" name="pesquisa" value="<?php echo $pesq1; ?>">
		<input type="submit" value="Pesquisar">
	</form>
	<p align="center">
	
<?php
	if ($pesq !='')
		echo "<center><a style='border-style: solid; padding:4px; border-width: thin;' href=index.php?cmd=lister>Listar todos os terceiros </a></center>";
?>

<?php
	$sql="select  * from Terceiros where 1=1 ";
	if ($pesq !='')
		$sql.=" and upper(Numero) like upper('$pesq') ";
	$sql.=" ORDER BY Numero limit $ini, $tp";
	$res=$lig->query($sql);

?>

<div class="container" align="center" >
	<p align="center">
	</div>
	<br><br>
	
	
<?php	
	if ($filtro !='')
		echo "<center><a style='border-style: solid; padding:4px; border-width: thin;' href=index.php?cmd=lister>Listar os terceiros </a></center>";
?>    
 	            
<div class="container">
  <h1 align="center">Listar Terceiros</h1> <br><br>      
  <table class="table table-striped">
    <thead>
	<tr>
      <tr>
	  <th colspan=2>
				<a href="index.php?cmd=addter">
				<button type="button" class="btn btn-success btn-lg">Adicionar Terceiro</button>
				</a>
			</th>
		</tr>	
       <th>Numero</th>
        <th>Cliente</th>
		<th>Fornecedor</th>
		<th>NIF</th>
		<th>Nome</th>
		<th>IdSiliamb</th>
		<th>Tipo</th>
		<th></th>
		<th></th>
      </tr>
    </thead>
    <tbody>
<?php
$sql = "SELECT Terceiros.*, Email, Telefone, Telemovel, TipoC, Morada, Localidade, CodPostal from Terceiros, Contactos_Terceiro, Morada_Terceiro ";
$sql.="WHERE Contactos_Terceiro.CodCon = Terceiros.CodCon and Morada_Terceiro.Numero = Terceiros.Numero  ";
$res=$lig->query($sql);         
while ($lin=$res->fetch_array()){ ?> 
      <tr>
        <td><?php echo$lin[Numero]; ?></td>
        <td><?php echo$lin[Cliente]; ?></td>
		<td><?php echo$lin[Fornecedor]; ?></td>
		<td><?php echo$lin[NIF]; ?></td>
		<td><?php echo$lin[Nome]; ?></td>
		<td><?php echo$lin[Idsiliamb]; ?></td>
		<td><?php echo$lin[Tipo]; ?></td>      
		                              
        <td><a href=index.php?cmd=editer&Numero=<?php echo$lin[Numero];?> title="Editar"><img src='Imagens/edit.png' width="20" height = "20" ></a></td>
		<td><a href=index.php?cmd=delter&Numero=<?php echo$lin[Numero];?> title="Apagar" onclick="return confirm('Tem a certeza que deseja apagar este registo?');" ><img src='Imagens/delete.png' width="20" height = "20" ></a></td>
		<td><td><button data-toggle = "modal" data-target = "#<?php echo$lin[Numero];?>" title="Visualizar" class="btn btn-default openBtn"><img src='Imagens/eye.png' width="20" height = "20" ><button></td></td>
      </tr> 
                                                                    <!-- Inicio do PopUp -->
								<div class="modal fade" id="<?php echo $lin['Numero']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">

									<div class="modal-dialog" role="document">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
												<h4 class="modal-title text-center" id="myModalLabel"><?php echo $lin['Nome']; ?></h4>
											</div>
									<div class="modal-body">
											    <div class="table-responsive">
                                                <div class="divTable blueTable">
                                                <div class="divTableHeading">
                                                <div class="divTableRow">
                                                    <div class="divTableHead">Telefone</div>
                                                    <div class="divTableHead">Telemovel</div>
                                                    <div class="divTableHead">Email</div>
                                                    <div class="divTableHead">Tipo</div>
                                                    <div class="divTableHead">Morada</div>
                                                    <div class="divTableHead">Localidade</div>
                                                    <div class="divTableHead">Codigo Postal</div>

                                                </div>
                                                </div>
                                                <div class="divTableBody">
                                                <div class="divTableRow">
                                                    <div class="divTableCell"><?php echo $lin['Telefone']; ?></div>
                                                    <div class="divTableCell"><?php echo $lin['Telemovel']; ?></div>
                                                    <div class="divTableCell"><?php echo $lin['Email']; ?></div>
                                                    <div class="divTableCell"><?php echo $lin['TipoC']; ?></div>
                                                    <div class="divTableCell"><?php echo $lin['Morada']; ?></div>
                                                    <div class="divTableCell"><?php echo $lin['Localidade']; ?></div>
                                                    <div class="divTableCell"><?php echo $lin['CodPostal']; ?></div>
                                                </div>
                                                </div>
                                                </div>

											   </div>
									</div>
									</div>
								    </div>
								                                 <!-- Fim do PopUp -->
								
								
<?php } ?>

    </tbody>
  </table>  
</div> 
<p align=center>
<?php	for ($i=1; $i<$qp; $i++)
		echo "<a href=index.php?cmd=lister&pag=$i&pesquisa=$pesq1>&nbsp$i&nbsp</a>";
?>
</p>

<!-- Aqui encontra-se o JOIN que mencionei anteriormente e o que se encontra igualmente no trecho de código acima. -->



<?php
$sql = "SELECT Terceiros.*, Email, Telefone, Telemovel, TipoC, Morada, Localidade, CodPostal from Terceiros, Contactos_Terceiro, Morada_Terceiro ";
$sql.="WHERE Contactos_Terceiro.CodCon = Terceiros.CodCon and Morada_Terceiro.Numero = Terceiros.Numero  ";
$res=$lig->query($sql); 

<?

  • " the search and pagination stopped working " need to explain better this so we can help, what stopped working? gives error, does not return value?

  • I regret not to have been explicit, when carrying out the search no changes are made, presents that there is more than one page but however when I click on the second page it presents exactly the same as the first and the data can be entered successfully but however are not presented

  • " through the realization of JOINS I was able to accomplish such task" if you made any changes it should also be used to back up the results, otherwise they might be different... the selects I saw in your code are different, should not be equal?

  • I mean, the select I made for popup should be the same for paging and searching?

  • at least the part of from, where and order by should be the same... I could not see well in your code because it is not complete, but imagine that you made a query that returns for example 100 results, and wants to page every 50, so it has two pages. . but if you do a different query then you can change the result of the total of pages and what should appear on each page

  • Could you show me where you needed to make the change please? Because I am not being able to see it

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.