Example : All-in-one multipurpose complete integrated report in PHP.

<?php
/* Page save as = cosreg_report.php*/
/*------------ Connectivity Codes ------------*/
error_reporting(E_ERROR | E_PARSE);
$conn = mysqli_connect("localhost", "root", "", "complaint");
if (!$conn) {
die("Connection Failed: " . mysqli_connect_error());
}
/*----- Fetching User's Value through HTML design for Search Record -----*/
$where = " WHERE 1=1 ";
/*(means start with a condition that is always true, so I can safely keep appending AND conditions later to report page with multiple search fields. It makes dynamic SQL query building easier and capable to return all records)*/
$sno3 = $name3 = $email3 = $gender3 = $blood3 = $city3 = $state3 = $from_date3 = $to_date3 = "";
if (isset($_POST['search']))
{
$sno3 = $_POST['sno1'];
$name3 = $_POST['name1'];
$email3 = $_POST['email1'];
$gender3 = $_POST['gender1'];
$blood3 = $_POST['blood1'];
$city3 = $_POST['city1'];
$state3 = $_POST['state1'];
$from_date3 = $_POST['from_date1'];
$to_date3 = $_POST['to_date1'];
if ($sno3 != "") {
$where .= " AND s5='$sno3' ";
}
if ($name3 != "") {
$where .= " AND fn5 LIKE '%$name3%' ";
}
if ($email3 != "") {
$where .= " AND em5 LIKE '%$email3%' ";
}
if ($gender3 != "") {
$where .= " AND gen5='$gender3' ";
}
if ($blood3 != "") {
$where .= " AND bg5='$blood3' ";
}
if ($city3 != "") {
$where .= " AND ct5 LIKE '%$city3%' ";
}
if ($state3 != "") {
$where .= " AND st5 LIKE '%$state3%' ";
}
if ($from_date3 != "" && $to_date3 != "") {
$where .= " AND dat5 BETWEEN '$from_date3' AND '$to_date3' ";
}
}
/*------------ Fetching All Record/s from MySql ------------*/
$sql = "SELECT * FROM cosreg $where ORDER BY s5 ASC";
$result = mysqli_query($conn, $sql);
if (!$result)
{
die("Query Error: " . mysqli_error($conn));
}
?>
<!DOCTYPE html>
<html>
<!-------------- Report Page HTML Design -------------->
<head>
<title>Customer Registration Report</title>
<!-------- Report Page CSS Code --------->
<style>
body {
font-family: Arial;
background: #eef3ff;
}
.container {
width: 98%;
margin: auto;
background: white;
padding: 20px;
margin-top: 20px;
border-radius: 10px;
box-shadow: 0 0 10px gray;
}
.header {
text-align: center;
border-bottom: 3px double black;
padding-bottom: 10px;
}
.header h2 {
margin: 0;
color: #003366;
}
.header p {
margin: 4px;
font-size: 14px;
}
.report-title {
text-align: center;
margin-top: 15px;
color: #b30000;
}
.search-box {
background: #e8f0ff;
padding: 15px;
border-radius: 8px;
margin-bottom: 15px;
}
.search-box table {
width: 100%;
}
.search-box td {
padding: 6px;
}
input,
select {
padding: 7px;
width: 95%;
}
button {
padding: 8px 18px;
border: none;
border-radius: 5px;
cursor: pointer;
color: white;
}
.search-btn {
background: #003366;
}
.print-btn {
background: green;
}
.refresh-btn {
background: black;
}
.report-box {
width: 100%;
height: 400px;
overflow: auto;
border: 2px solid #003366;
}
.report-table {
width: 2500px;
border-collapse: collapse;
font-size: 13px;
}
.report-table th {
background: #003366;
color: white;
padding: 8px;
position: sticky;
top: 0;
}
.report-table td {
border: 1px solid #ccc;
padding: 7px;
text-align: center;
}
.report-table tr:nth-child(even) {
background: #f2f2f2;
}
.footer {
margin-top: 15px;
font-weight: bold;
}
@media print {
@page {
size: landscape;
margin: 8mm;
}
body {
background: white;
}
.search-box,
.no-print {
display: none !important;
}
.container {
width: 100%;
margin: 0;
padding: 0;
box-shadow: none;
border: none;
}
.report-box {
height: auto;
overflow: visible;
border: none;
}
.report-table {
width: 100%;
font-size: 8px;
}
.report-table th {
position: static;
background: #d9d9d9 !important;
color: black !important;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
.report-table th,
.report-table td {
border: 1px solid black;
padding: 3px;
word-break: break-word;
}
tr {
page-break-inside: avoid;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>CUSTOMER COMPLAINT MANAGEMENT SYSTEM</h2>
<h3>Customer Registration Report</h3>
<p>Generated Date: <?php echo date("d-m-Y"); ?></p>
</div>
<h3 class="report-title">Customer Registration Multi Purpose Report</h3>
<div class="search-box no-print">
<form method="post">
<table>
<tr>
<td>Serial No</td>
<td><input type="text" name="sno1" value="<?php echo $sno3; ?>"></td>
<td>Name</td>
<td><input type="text" name="name1" value="<?php echo $name3; ?>"></td>
<td>Email</td>
<td><input type="text" name="email1" value="<?php echo $email3; ?>"></td>
</tr>
<tr>
<td>Gender</td>
<td>
<select name="gender1">
<option value="">All</option>
<option value="Male" <?php if ($gender3 == "Male")
echo "selected"; ?>>Male</option>
<option value="Female" <?php if ($gender3 == "Female")
echo "selected"; ?>>Female</option>
<option value="Others" <?php if ($gender3 == "Others")
echo "selected"; ?>>Others</option>
</select>
</td>
<td>Blood Group</td>
<td>
<select name="blood1">
<option value="">All</option>
<option value="A+" <?php if ($blood3 == "A+")
echo "selected"; ?>>A+</option>
<option value="A-" <?php if ($blood3 == "A-")
echo "selected"; ?>>A-</option>
<option value="B+" <?php if ($blood3 == "B+")
echo "selected"; ?>>B+</option>
<option value="B-" <?php if ($blood3 == "B-")
echo "selected"; ?>>B-</option>
<option value="O+" <?php if ($blood3 == "O+")
echo "selected"; ?>>O+</option>
<option value="O-" <?php if ($blood3 == "O-")
echo "selected"; ?>>O-</option>
<option value="AB+" <?php if ($blood3 == "AB+")
echo "selected"; ?>>AB+</option>
<option value="AB-" <?php if ($blood3 == "AB-")
echo "selected"; ?>>AB-</option>
</select>
</td>
<td>City</td>
<td><input type="text" name="city1" value="<?php echo $city3; ?>"></td>
</tr>
<tr>
<td>State</td>
<td><input type="text" name="state1" value="<?php echo $state3; ?>"></td>
<td>From DOB</td>
<td><input type="date" name="from_date1" value="<?php echo $from_date3; ?>"></td>
<td>To DOB</td>
<td><input type="date" name="to_date1" value="<?php echo $to_date3; ?>"></td>
</tr>
<tr>
<td colspan="6" align="center">
<button type="submit" name="search" class="search-btn">Search Report</button>
<button type="button" class="refresh-btn"
onclick="window.location.href='cosreg_report.php'">
Refresh
</button>
<button type="button" class="print-btn" onclick="window.print()">
Print Preview / Print
</button>
</td>
</tr>
</table>
</form>
</div>
<!---------- Report Page Header Code ---------->
<div class="report-box">
<table class="report-table">
<tr>
<th>Sl.No.</th>
<th>Full Name</th>
<th>Email</th>
<th>DOB</th>
<th>Gender</th>
<th>Blood Group</th>
<th>Phone</th>
<th>Alternate No.</th>
<th>Aadhaar No.</th>
<th>Current Address</th>
<th>Permanent Address</th>
<th>City</th>
<th>State</th>
<th>Pincode</th>
<th>Username</th>
<th>Password</th>
<th>Confirm Password</th>
<th>Remarks</th>
</tr>
<!---------- Report Page with MySql Records Code ---------->
<?php
$count = 0;
if (mysqli_num_rows($result) > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
$count++;
?>
<tr>
<td><?php echo $row['s5']; ?></td>
<td><?php echo $row['fn5']; ?></td>
<td><?php echo $row['em5']; ?></td>
<td><?php echo $row['dat5']; ?></td>
<td><?php echo $row['gen5']; ?></td>
<td><?php echo $row['bg5']; ?></td>
<td><?php echo $row['pn5']; ?></td>
<td><?php echo $row['an5']; ?></td>
<td><?php echo $row['adh5']; ?></td>
<td><?php echo $row['ad5']; ?></td>
<td><?php echo $row['pad5']; ?></td>
<td><?php echo $row['ct5']; ?></td>
<td><?php echo $row['st5']; ?></td>
<td><?php echo $row['pc5']; ?></td>
<td><?php echo $row['nue5']; ?></td>
<td><?php echo $row['pas5']; ?></td>
<td><?php echo $row['cpas5']; ?></td>
<td><?php echo $row['rem5']; ?></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="18"><b><i>No Record/s Found</b></i></td>
</tr>
<?php
}
?>
</table>
</div>
<div class="footer">
Total Records: <?php echo $count; ?>
</div>
</div>
</body>
</html>
![]()
0 Comments