-
-
Save facumartig/6054971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'config/db_config.php'; | |
$sql = "SELECT *, DATE_FORMAT(timestamp, '%Y-%c-%e') selector FROM events WHERE DATE_FORMAT(timestamp, '%Y-%c') = '".$_POST['d']."' ORDER BY timestamp, id ASC"; | |
$query = mysqli_query($link, $sql); | |
if (mysqli_num_rows($query) > 0){ | |
$data = array(); | |
while ($recset = mysqli_fetch_array($query)){ | |
if(!array_key_exists($recset["selector"], $data)){ | |
$data[$recset["selector"]] = array($recset); | |
}else{ | |
array_push($data[$recset["selector"]],$recset); | |
} | |
} | |
$data['rows'] = mysqli_num_rows($query); | |
echo json_encode($data); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (i = 1; i <= days_number; i++) { | |
if (m === actual_m && diap === actual_d) { | |
tbody.append("<td id=\"" + y + "-" + m + "-" + diap + "\" class=\"actual\"><span><a href=\"#myModal\" role=\"button\" class=\"days\" data-toggle=\"modal\">" + diap + "</a></span></td>"); | |
} | |
else { | |
tbody.append("<td id=\"" + y + "-" + m + "-" + diap + "\"><span><a href=\"#myModal\" role=\"button\" class=\"days\" data-toggle=\"modal\">" + diap + "</a></span></td>"); | |
} | |
if (i % 7 === 0) { tbody.append("</tr><tr>"); } | |
if (diap === days_number) { break; } | |
diap++; | |
} | |
$.ajax({ | |
dataType: "json", | |
url: "./php/date2.php", | |
type: "POST", | |
data: { d: y + "-" + m }, | |
success: function(data) { | |
Object.size = function(obj) { | |
var size = 0, key; | |
for (key in obj) { | |
if (obj.hasOwnProperty(key)) size++; | |
} | |
return size; | |
}; | |
console.log(data); | |
for (key in data) { | |
$("<span class=\"badge badge-info\">" + Object.size(data[key]) + "</span>").prependTo($("#" + key)); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment