-
Notifications
You must be signed in to change notification settings - Fork 0
/
consultaPaginada.php
43 lines (38 loc) · 981 Bytes
/
consultaPaginada.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
function consulta_paginada( $conn, $query, $pag_num, $pag_size )
{
try {
$primera = ( $pag_num - 1 ) * $pag_size + 1;
$ultima = $pag_num * $pag_size;
$consulta_paginada =
"SELECT * FROM ( "
."SELECT ROWNUM RNUM, AUX.* FROM ( $query ) AUX "
."WHERE ROWNUM <= :ultima"
.") "
."WHERE RNUM >= :primera";
$stmt = $conn->prepare( $consulta_paginada );
$stmt->bindParam( ':primera', $primera );
$stmt->bindParam( ':ultima', $ultima );
$stmt->execute();
return $stmt;
}
catch ( PDOException $e ) {
$_SESSION['excepcion'] = $e->GetMessage();
header("Location: excepcion.php");
}
}
function total_consulta( $conn, $query )
{
try {
$total_consulta = "SELECT COUNT(*) AS TOTAL FROM ($query)";
$stmt = $conn->query($total_consulta);
$result = $stmt->fetch();
$total = $result['TOTAL'];
return $total;
}
catch ( PDOException $e ) {
$_SESSION['excepcion'] = $e->GetMessage();
header("Location: excepcion.php");
}
}
?>