Paging does not work

Asked

Viewed 63 times

0

I just did the research field and paging of my project, however I have 17 records already added but only has 8 records I made the code in order to present 15 records per page, that is, on the second page should appear the 2 records that are missing. However warns that there are 2 pages, but the second page is empty.

<?php
	$sql="select * from Terceiros";
	$res=$lig->query($sql);
?>

	<head><meta http-equiv="Content-Type" content="text/html; charset=gb18030">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">

			<meta name="viewport" content="initial-scale=1.0; maximum-scale=1.0; width=device-width;">

		           <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
	</head>

<?php
//paginação
	$tp=15;
	if (isset($_REQUEST['pesquisa'])) 
		$pesq='%'.$_REQUEST['pesquisa'].'%'; 
	
	if (isset($_REQUEST['pag'])) 
		$np=$_REQUEST['pag']; 
	else 
		$np=1;
	$ini=($np-1)*$tp;
	
	$sql="select * from Terceiros";
	if(isset($pesq))
		$sql.=" where Nome like '$pesq'";
	$res=$lig->query($sql);
	$nr=$res->num_rows;
	$qp=$nr/$tp+1;
//Fim paginação	
		
	$sql="SELECT Terceiros.*, Email, Telefone, Telemovel, TipoC, Morada, Localidade, CodPostal FROM ((Terceiros INNER JOIN  Contactos_Terceiro on  Terceiros.CodCon = Contactos_Terceiro.CodCon ) INNER JOIN Morada_Terceiro on Terceiros.Numero = Morada_Terceiro.Numero )";
	if(isset($pesq))
	$sql.=" where Nome like '$pesq'";
	$sql.=" limit $ini, $tp";
	$res=$lig->query($sql);
?>

		

<div class="container">
  <h1 align="center">Listar Terceiros</h1> <br><br>      
  <table class="table table-striped">
    <thead>
	<tr>
      <tr>		
			<th colspan=3>
			<form method="POST" class="form-inline" action="index.php?cmd=lister">
			  <div class="form-group">
				<label for="Pesquisa" >Pesquisar Terceiros: </label>
				<input type="text" class="form-control" id="pesquisa" name="pesquisa">
				<button type="submit" class="btn btn-default">Pesquisar</button>
			  </div>
			</form>
			</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> 
   
<?php  } ?>

    </tbody>
  </table>  
  
<?php	//Paginação 
	for ($i=1; $i<$qp; $i++)
		echo "<a href=index.php?cmd=lister&pag=$i>&nbsp$i&nbsp</a>";
?>
        
</div> 

  • Printa the $sql last query to see how are the pagination values

  • Appeared as follows: " SELECT Third Parties.*, Email, Phone, Phone, Typoc, Address, Locality, Codpostal FROM ((Third parties INNER JOIN Contactos_terceiro on Terceiros.Codcon = Contactos_terceiro.Codcon ) INNER JOIN Address_terceiro on Terceiros.Numero = Address_terceiro.Numero ) Where Name like '%Joaquim%' limit 0, 15 "

  • Test in the direct seat to see if the answer is correct or if an error appears

  • Right bank??

  • Using an IDE or command line to run the query in the database without using PHP

  • I tried to follow his advice, but he didn’t make a mistake

  • and the return has how many records? is correct? simulates paging by changing the values in the query

  • The reality is that nothing returned, I do not know what happened

Show 3 more comments
No answers

Browser other questions tagged

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