This repository has been archived by the owner on Mar 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_results.php
108 lines (93 loc) · 3.37 KB
/
search_results.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php require_once('./header.php');?>
<div class="container">
<div class="row">
<div class="col-md-3">
<a href="insert.php" class="btn btn-default">New Register</a>
</div>
<div class="col-md-9">
<form action="search.php" method="get" >
<div class="pull-right"style="padding-left: 0;" >
<span class="pull-right">
<label class="col-lg-12 control-label" for="keyword" style="padding-right: 0;">
<input type="text" value="<?=$_GET["keyword"]?>" placeholder="Name" class="form-control" name="keyword">
</label>
</span>
<button class="btn btn-info">search</button>
</div>
</form>
</div>
</div>
</div>
<br>
<?php
// Connect to database.
include './db_connect.php';
// Include our pagination class / library.
include './libs/ps_pagination.php';
// Query all data anyway you want
$sql = "select * from $table order by id";
/*
Now, we are going to use our pagination class.
This is a significant part of our pagination.
I will explain the PS_Pagination parameters:
> $pdo is a variable from our config_open_db.php
> $sql is our sql statement above
> 3 is the number of records retrieved per page
> 4 is the number of page numbers rendered below
> null - We used null because we don't have any other parameters to pass
(i.e. param1=valu1¶m2=value2)
You can use this if you are going to use this class for search results.
The last parameter is useful because you will have to pass the search keywords.
*/
// PS_Pagination($pdoection, $sql, $rows_per_page = 10, $links_per_page = 15, $append = "")
$pager = new PS_Pagination($pdo, $sql, 15, 23);
// Our pagination class will render new recordset.
// Search results now are limited for pagination.
$rs = $pager->paginate();
// Count how many rows of data were returned.
$num = $rs->rowCount();
if($num >= 0 ){
// Create our table header
print '<div class="container" align="center">';
echo '<table class="table table-hover">';
echo "<tr>";
$sth = $pdo->query($sql);
$numfields = $sth->columnCount();
for($x=0;$x<$numfields;$x++){
$meta = $sth->getColumnMeta($x);
$field = $meta['name'];
?>
<th><?=ucfirst($field)?></th>
<?php
}
print '<th colspan="2">Action</th>';
echo "</tr>";
// Loop through the records retrieved
while ($row = $rs->fetch(PDO::FETCH_ASSOC)){
echo "<tr>";
for($x=0;$x<$numfields;$x++){
$meta = $sth->getColumnMeta($x);
$field = $meta['name'];
?>
<td><?=$row[$field]?></td>
<?php
}
?>
<td><a href="update.php?id=<?=$row['id']?>"><i class="glyphicon glyphicon-edit" title="Update"></a></td>
<td><a href="delete.php?id=<?=$row['id']?>"><i class="glyphicon glyphicon-remove-circle" title="Delete"></a></td></tr>
<?php
echo "</tr>";
}
echo "</table>";
}else{
// If no records found
echo "None register found!";
}
// 'page-nav' CSS class is used to control the appearance of our page number navigation
echo "<div class='page-nav' align='center'>";
// Display our page number navigation
echo $pager->renderFullNav();
echo "</div>";
?>
</div>
<?php require_once('./footer.php'); ?>