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.php
68 lines (56 loc) · 1.79 KB
/
search.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
<?php
require_once('./header.php');
include './db_connect.php';
// Busca
if(isset($_GET['keyword'])){
$keyword=$_GET['keyword'];
$sql = "select * from $table";
$sth = $pdo->prepare($sql);
$sth->execute();
$meta = $sth->getColumnMeta(1);
$field = $meta['name'];
$sql = "select * from $table WHERE $field LIKE :keyword order by id";
$sth = $pdo->prepare($sql);
$sth->bindValue(":keyword", $keyword."%");
$sth->execute();
$rows =$sth->fetchAll(PDO::FETCH_ASSOC);
}
print '<div class="container" align="center">';
print '<h4>Registro(s) encontrado(s)</h4>';
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">Ação</th>';
echo "</tr>";
// Loop through the records retrieved
foreach ($rows as $row){
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="Edit"></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>";
?>
<input name="enviar" class="btn btn-warning" type="button" onclick="location='index.php?table=<?=$table?>'" value="Back">
</div>
<?php
require_once('./header.php');
?>