CREATE TABLE `login` ( `logid` INT(11) NOT NULL AUTO_INCREMENT, `username` VARCHAR(30) NOT NULL, `login_date` datetime NOT NULL, PRIMARY KEY(`logid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `login` (`username`, `login_date`) VALUES ('nurhodelta', '2017-08-22 07:10:00'), ('lee', '2017-05-22 08:30:00'), ('nurhodelta', '2017-08-22 13:15:00'), ('lee', '2017-03-22 14:00:00'), ('nurhodelta', '2017-05-16 10:30:00'), ('lee', '2017-08-15 20:00:00');
<?php //MySQLi Procedural if (!$conn) { } //MySQLi Object-oriented //$conn = new mysqli("localhost","root","","month_year"); //if ($conn->connect_error) { // die("Connection failed: " . $conn->connect_error); //} ?>
<!DOCTYPE html> <html> <head> <title>Select Data By Month and Year</title> </head> <body> <h2>Login Table</h2> <div> <table border="1"> <thead> <th>UserID</th> <th>Username</th> <th>Login Date</th> </thead> <tbody> <?php include('conn.php'); //MySQLi Procedural ?> <tr> <td><?php echo $row['logid']; ?></td> <td><?php echo $row['username']; ?></td> <td><?php echo $row['login_date']; ?></td> </tr> <?php } //MySQLi Object-oriented //$query=$conn->query("select * from `login`"); //while($row = $query->fetch_array()) { /* ?> <tr> <td><?php echo $row['logid']; ?></td> <td><?php echo $row['username']; ?></td> <td><?php echo $row['login_date']; ?></td> </tr> <?php */ //} ?> </tbody> </table> </div><br> <div> <form method="POST"> <label>Month: </label> <select name="month"> <?php for ($i = 1; $i <= 12; $i++) { ?> <option value="<?php echo $i; ?>"><?php echo $month; ?></option> <?php } ?> </select> <label>Year: </label> <select name="year"> <?php for($n=2017;$n<=2050;$n++){ ?> <option value="<?php echo $n; ?>"><?php echo $n; ?></option> <?php } ?> </select> <input type="submit" value="Get Data" name="submit"> </form> </div> <h2>Data in Selected Month and Year</h2> <div> <table border="1"> <thead> <th>UserID</th> <th>Username</th> <th>Login Date</th> </thead> <tbody> <?php include('conn.php'); $month=$_POST['month']; $year=$_POST['year']; //MySQLi Procedural $oquery=mysqli_query($conn,"select * from `login` where month(login_date)='$month' and year(login_date)='$year'"); echo "No data Found."; } else{ ?> <tr> <td><?php echo $orow['logid']?></td> <td><?php echo $orow['username']?></td> <td><?php echo $orow['login_date']?></td> </tr> <?php } } //MySQLi Object-oriented //$oquery=$conn->query("select * from `login` where month(login_date)='$month' and year(login_date)='$year'"); //if ($oquery->num_rows <= 0) { // echo "No data Found."; //} //else{ //while($orow = $oquery->fetch_array()){ /* ?> <tr> <td><?php echo $orow['logid']?></td> <td><?php echo $orow['username']?></td> <td><?php echo $orow['login_date']?></td> </tr> <?php */ //} //} } ?> </tbody> </table> </div> </body> </html>
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.