I have a selection menu with month names (values are numbers from 1 to 12):
Inside I want to fetch data from database. So if chosen October then shows tournaments of October and so on...
SQL code is right (tested).
It looks like ajax is not even finding fetch_tournaments.php file... or maybe just somewhere I made a mistake...
My AJAX:
$(document).ready(function(){
$('#monthSelector').change(function(){
var month = $(this).val();
alert(month);
$.ajax({
url:"../../includes/functions/ajax/fetch_tournaments.php",
method:"POST",
data:{month: month},
dataType:"text",
success:function(data)
{
$('#tournamentList').html(data);
}
});
});
});
fetch_tournaments.php:
<?php
require_once '../../../config/init.php';
$sql = "SELECT * FROM tournaments WHERE itfnt = 'ITF' AND MONTH(date) = '".$_POST["month"]."' ORDER BY date ASC";
$result = $mysqli->query($sql);
$num_rows = $result->num_rows;
if($num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<div class="col-md-6">
<div class="card">
<div class="card-block">
<h6 class="category text-danger">
<i class="now-ui-icons location_pin"></i> Latvia, Riga
</h6>
<h5 class="card-title">
<a href="#pablo">RIGA AUTUMN CUP 1</a>
</h5>
<div class="card-footer">
<div class="author">
<img src="assets/img/lpts.png" alt="..." class="avatar img-raised">
<span>LPTS</span>
</div>
<div class="stats stats-right">
<i class="now-ui-icons ui-1_calendar-60"></i> 25.10.17
</div>
</div>
</div>
</div>
</div>
';
}
} else {
echo 'No tournaments that month';
}
?>
Solved... there was a typo