-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist.php
More file actions
101 lines (89 loc) · 2.64 KB
/
list.php
File metadata and controls
101 lines (89 loc) · 2.64 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="studentlister" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
List by name:<input type="text" name="name" /><br />
Alternatively, List students of Class
<select name="select-class">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input type="submit" name="submit" value="List" />
</form>
</body>
<?php
$main="main";
include("connectdb.php");
if (!empty($_POST['name'])){
$myname = $_POST['name'];
$sql="SELECT * FROM `$main` where name like '%$myname%'";
$result = mysql_query($sql) or die(mysql_error());
if($result)
{
$num = mysql_numrows($result);
echo "<table border=1 width=400 align=center><tr><td>"."Name"."</td><td>Class</td><td>Roll</td>"."</tr>";
for($k=0; $k<$num; $k++)
{
$row=mysql_fetch_array($result);
$id[$k]=$row['ID'];
$name[$k]=$row['name'];
$roll[$k]=$row['roll'];
$class[$k]=$row['class'];
?>
<tr><td>
<a href="viewdetails.php?sid=<?php echo $id[$k]; ?>"><?php echo $name[$k];?></a></td><td><?php echo $class[$k];?></td><td><?php echo $roll[$k]."</td></tr>";?>
<?php }
?>
</table>
<?php
}
}
else if (!empty($_POST['select-class'])){
$myclass = $_POST['select-class'];
echo "Class::".$myclass;
$sql="SELECT * FROM `$main` where class=$myclass ORDER BY roll";
$result = mysql_query($sql) or die(mysql_error());
if($result)
{
$num = mysql_num_rows($result);
echo "<table border=1 width=400 align=center><tr><td>"."Name"."</td><td>Roll</td>"."</tr>";
for($k=0; $k<$num; $k++)
{
$row=mysql_fetch_array($result);
$id[$k]=$row['ID'];
$name[$k]=$row['name'];
$roll[$k]=$row['roll'];
?>
<tr><td>
<a href="viewdetails.php?sid=<?php echo $id[$k]; ?>"><?php echo $name[$k];?></a></td><td><?php echo $roll[$k]."</td></tr>";?>
<?php
}?>
</table>
<?php
}
}
?>
<section id="menu">
<nav>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="studentadder.php">Add Student</a></li>
<li><a href="list.php">List Students</a></li>
<li>Edit Student Info</li>
</ul>
</nav>
</section>
</body>
</html>