-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfetch_data.php
42 lines (34 loc) · 1.29 KB
/
fetch_data.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
<?php
require_once('./functions/crud.php');
$pdo = connection();
if (isset($_POST["page"])) {
$page_no = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
if(!is_numeric($page_no))
die("Error fetching data! Invalid page number!!!");
} else {
$page_no = 1;
}
// get record starting position
$start = (($page_no-1) * $regsPerPage);
if($sgbd == 'mysql'){
$results = $pdo->prepare("SELECT * FROM $table ORDER BY id DESC LIMIT $start, $regsPerPage");
}else if($sgbd == 'pgsql'){
$results = $pdo->prepare("SELECT * FROM $table ORDER BY id DESC LIMIT $regsPerPage OFFSET $start");
}
$results->execute();
$nr = $results->rowCount();
if($nr > 0){
while($row = $results->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>" . rowFields($row);
$id = $row['id'];
$name = $row['name'];
?>
<td><a href="update.php?id=<?=$row['id']?>&table=<?=$table?>"><i class="glyphicon glyphicon-edit" title="Update"></a></td>
<td><a onclick="return confirm('Realmente excluir o cliente <?=$name?> ?')" href="delete.php?id=<?=$id?>&table=<?=$table?>"><i class="glyphicon glyphicon-remove-circle" title="Delete"></a></td></tr>
<?php
print "
</tr>";
}
}else{
echo '<h3 class="bg-danger">None register found!</h3>';
}