Select MySQLi Data By Monthly Using PHP | CampCodes

Select MySQLi Data By Monthly using PHP

July 1, 2020
select mysqli data by monthly using php

In this tutorial, we will create a Select MySQLi Data By Monthly using PHP. This code will select a specific MySQLi table row when the user submits a month and year from a form. The code use MySQLi SELECT query to select data in the MySQLi row, and by providing a month and year in the WHERE clause, it will display that particular database on the given month and year. This a user-friendly program; feel free to modify and use it to your system.

We will be using PHP as a scripting language and interpreter that is used primarily on any web server, including xamp, wamp, etc. It is being used to any popular websites because of the modern approach as its today.

Getting Started:

First, you have to download & install XAMPP or any local server that runs PHP scripts. Here’s the link for the XAMPP server

And, this is the link for the bootstrap that I used for the layout design

Creating Database

Open your database web server then create a database name in it db_month, after that, click Import, then locate the database file inside the folder of the application then click ok.

2019 10 30 23 20 23 localhost db detail phpmyadmin 4.8.3

Creating the database connection

Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php.

    $conn=mysqli_connect("localhost", "root", "", "db_month");
        die("Error: Failed to connect to database!");

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.

<!DOCTYPE html>
<html lang="en">
        <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
        <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <a class="navbar-brand" href="">Sourcecodester</a>
    <div class="col-md-3"></div>
    <div class="col-md-6 well">
        <h3 class="text-primary">PHP - Select MySQLi Data By Monthly</h3>
        <hr style="border-top:1px dotted #ccc;"/>
        <div class="col-md-2"></div>
        <div class="col-md-8">
            <form method="POST" action="">
                <div class="form-inline">
                    <label>Month: </label>
                    <select name="month" class="form-control">
                            for ($i = 1; $i <= 12; $i++){
                                $month = date('F', mktime(0, 0, 0, $i, 1, 2019));
                                <option value="<?php echo $i; ?>"><?php echo $month; ?></option>
                    <label>Year: </label>
                    <select name="year" class="form-control">
                            for ($i = date('Y'); $i >= 1965; $i--){
                            <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
                    <button class="btn btn-primary" name="search">Search</button>
            <h4>Selected: <span class="text-primary"><?php if(ISSET($_POST['search'])){echo date("F", mktime(null, null, null, $_POST['month']));}?></span> <span class="text-primary"><?php if(ISSET($_POST['search'])){echo $_POST['year'];}?></span></h4>
            <table class="table table-bordered">
                <thead class="alert-info">
                        <th>Data Joined</th>
                    <?php include'search.php'?>

Creating the Main Function

This code contains the main function of the application. This code will select a specific MySQLi table row when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as search.php

        $query=mysqli_query($conn, "SELECT * FROM `member` WHERE month(date_joined)='$month' AND year(date_joined)='$year'") or die(mysqli_error());
            echo "<tr><td>".$fetch['firstname']."</td><td>".$fetch['lastname']."</td><td>".$fetch['date_joined']."</td></tr>";
        $query=mysqli_query($conn, "SELECT * FROM `member`") or die(mysqli_error());
            echo "<tr><td>".$fetch['firstname']."</td><td>".$fetch['lastname']."</td><td>".$fetch['date_joined']."</td></tr>";

There you have it we successfully created Select MySQLi Data By Monthly using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!


PHP - Select MySQLi Data By Monthly Source Code 339 KB 361 downloads

Please go back to the description page. Just Click the Red Download Button on the...

This is a free education portal. You can use every source code in your project without asking permission to the author. Share our website to everyone to make our community of programmers grow more.

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *