-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchType.php
85 lines (79 loc) · 2.3 KB
/
SearchType.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
<?php
include("dbconnect.php");
include("home.php") ;
$mysqli -> query('set names utf8');
if(!isset($_POST['typeName'])) // other
{
$_POST['typeName'] = $_SESSION['searchByType'];
$ss = $_POST['typeName'];
$get = "select * from 食譜類型 where 食譜類型 = '$ss'";//?
$data = $mysqli ->query($get);
$number= 5 ;//每次要顯示幾筆資料
$total = mysqli_num_rows($data);//總共有幾筆資料
$pages = ceil($total/$number);//透過無條件進位法,算出需要幾頁
}
else // first
{
$inputName = $_POST['typeName'];
$get = "select * from 食譜類型 where 食譜類型 = '$inputName'";
$data = $mysqli ->query($get);
$number = 5 ;//每次要顯示幾筆資料
$total = mysqli_num_rows($data);//總共有幾筆資料
$pages = ceil($total/$number);//透過無條件進位法,算出共需要幾頁
$_SESSION['searchByType'] = $inputName;
}
if(!isset($_GET['p']))
{
$p=1;
$_SESSION['getP'] = $p;
}
else
{
$p = $_GET['p'];
}
//用來呈現資料
$s = $_SESSION['searchByType'];
$start=($p-1)*$number;
$set = "select * from 食譜類型 where 食譜類型 = '$s' limit $start , $number";
$data = $mysqli ->query($set);
?>
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset=utf-8" >
<title>根據資料筆數顯示</title>
</head>
<body>
<?php
echo '<center><div class = "frame"><table>';
echo '<thead><tr>';
echo '<td>食譜名稱</td></tr></thead><tbody>';?>
<?php
for($i=1;$i<=mysqli_num_rows($data);$i++)
{
echo '<tr>';
while($check = $data->fetch_object())
{
echo '<tr><td><a class = "searchResult" href=recipe.php?recipe="'.$check -> 菜名.'">'.$check -> 菜名.'</a></td>';
}
echo '</tr>';
}
echo '</tbody></table></div></center>';
?>
<p style="text-align: center">
<?php
for($i=1;$i<=$pages;$i++)
{
echo "<a href=SearchType.php?p=$i style=\"border-style:solid;text-decoration: none;color:black\">"." ".$i." "."</a>";
echo " ";
}
if($pages == 0)
{
$pages = 1;
echo "查無資料";
}
?>
</p>
<p style="text-align: center">第<?php echo $p?>頁/共有<?php echo $pages?>頁</p>
</body>
</html>