vendredi 10 juin 2016

how to get events from data base depending on month selected


I have events stored in my database in the format 2016-12-05, ie 5th December 2016.

I am using HTML 5 month picker so users can see all events in a particular month.

My question is how can I edit the sql so it can recognise the above date should be selected if they chose December 2016.

HTLM code:

    <form method="post" name="Month" id="Month">
    <input type="month" name="month" id="month"/>
    <input type="submit" value="Select"/>

The PHP code:

    $month = $_POST['month'];
    if (isset($_POST['month'])){
        $sql = "SELECT * FROM training WHERE groupName='$group' && sessDate='$month' ORDER BY sessdate ASC";
    $training_query = mysqli_query($db_conx, $sql);
    }

If I get rid of the month picker stuff it all works fine, $group is established higher up on the page. sessDate is stored as date in the database.

If i remove it all it shows every event ever created.

I am thinking I may need to use ajax or something as when I hit select the page obviously refreshes and the month picker is empty again. My knowledge of ajax and java script is very poor though so any help would be much appreciated.


Aucun commentaire:

Enregistrer un commentaire