Here I'm going to access data in the database and trying to display those data on the browser using a dynamic table. For that task I'll use simple interface to perform certain search operations. I apply these scenarios to create admin part of my project. Here is the snapshot of that sample interface.
Here we can perform date wise and type wise search. For that I'll publish sample php code with html5 design here..!
<html>
<head>
//put certain external CSS link here to apply styles to your interface as above.
</head>
<body>
<form id="membSearch" action="" method="post">
<table width="800" height="140" border="0" align="center">
<tr>
<td align="center"> <b>Search by Register Date : </b> </td>
</tr>
<tr>
<td> <?php echo "<br>"; ?> </td>
</tr>
<tr>
<td width="120" align="center">Date: <input type="date" name="regDate"
id='regDate' class='datepicker' readonly/></td>
<td width="146">
<input type="submit" name="dateSearch" value="Search" onclick=""/>
</td>
</tr>
<tr>
<td> <?php echo "<br>"; ?> </td>
</tr>
<tr>
<td align="center"> <b>Search by Type : </b> </td>
</tr>
<tr>
<td align="center">
<select name="comboVolunType" id="comboVolunType">
<option>Field Work</option>
<option>Veterinary Work</option>
</select>
</td>
<td><input type="submit"value="search" name="volType"/></td>
</tr>
<?php
function checkEmptyResult($resultTable) {
$num_of_rows = mysql_num_rows($resultTable);
if ($num_of_rows == NULL) {
echo '<script type="text/javascript">alert("No results found");</script>';
echo '<script type="text/javascript">history.go(-1);</script>';
}
}
if (isset($_POST['dateSearch'])) {
include ('../../controllers/db.php');
$regDate = $_POST['regDate'];
$queryTable = "SELECT * FROM eop_volunteers WHERE regDate>= '$regDate' and status =1";
$resultTable = mysql_query($queryTable);
checkEmptyResult($resultTable);
echo"<table border = '1' cellpadding = '3' cellspacing = '2' width = '600' align = 'center'>
<tr>
<th>Email</th>
<th>First Name</th>
<th>Surname</th>
<th>DOB</th>
<th>Address</th>
<th>Phone</th>
<th>Gender</th>
<th>Reg Date</th>
<th>Country</th>
<th>Skills</th>
</tr>";
while ($row = mysql_fetch_array($resultTable)) {
echo "</td><td>";
echo $row['email'];
echo "</td><td>";
echo $row['fname'];
echo "</td><td>";
echo $row['lname'];
echo "</td><td>";
echo $row['date'];
echo "</td><td>";
echo $row['address'];
echo "</td><td>";
echo $row['phone'];
echo "</td><td>";
$gen = $row['gender'];
if($gen == 1){
echo "Male";
}else {
echo "Female";
}
//echo $row['gender'];
echo "</td><td>";
echo $row['regDate'];
echo "</td><td>";
echo $row['country'];
echo "</td><td>";
echo $row['skills'];
echo "</td></tr>";
}
} else if (isset($_POST['volType'])) {
include ('../../controllers/db.php');
$volWork = $_POST['comboVolunType'];
$queryTable = "SELECT * FROM eop_volunteers WHERE volunType= '$volWork' and status=1";
$resultTable = mysql_query($queryTable);
checkEmptyResult($resultTable);
echo"<table border = '1' cellpadding = '3' cellspacing = '2' width = '1000' align = 'center'>
<tr>
<th>Email</th>
<th>First Name</th>
<th>Surname</th>
<th>DOB</th>
<th>Type</th>
<th>Address</th>
<th>Phone</th>
<th>Gender</th>
<th>Country</th>
<th>Skills</th>
</tr>";
while ($row = mysql_fetch_array($resultTable)) {
echo "</td><td>";
echo $row['email'];
echo "</td><td>";
echo $row['fname'];
echo "</td><td>";
echo $row['lname'];
echo "</td><td>";
echo $row['date'];
echo "</td><td>";
echo $row['volunType'];
echo "</td><td>";
echo $row['address'];
echo "</td><td>";
echo $row['phone'];
echo "</td><td>";
$gen = $row['gender'];
if($gen == 1){
echo "M";
}else{
echo "F";
}
echo "</td><td>";
echo $row['country'];
echo "</td><td>";
echo $row['skills'];
echo "</td></tr>";
}
}
// }
?>
</table>
</body>
</html>
No comments:
Post a Comment