I’m trying to evaluate the value of id
, which should be passed in the POST from jQuery to PHP.
The call is returning {'id':'99'}
, which is ok if id
is not equal to 0. I wonder why ($x == "0")
is not being evaluated to true
in my PHP function.
Any help would be greatly appreciated! Thanks in advance.
jQuery:
$( document ).ready(function() {
$.ajax({
url: '/more.php',
type: 'POST',
data: JSON.stringify({"id" : "0"}),
success: function(data) {
$("body").append(data);
}
});
});
PHP:
if (isset($_POST['id'])) {
$con=mysqli_connect("localhost","user","pass","schema");
getmore($_POST['id']);
function getmore($x) {
if ($x == "0") {
$sqldata = mysqli_query($con,"SELECT * FROM IRCLOG WHERE DATETIME >= date_sub(curdate(),interval 1 day)");
}
else {
$sqldata = mysqli_query($con,"SELECT * FROM IRCLOG WHERE DATETIME >= date_sub(curdate(),interval 1 day)");
}
// your business logic
$rows = array();
while($r = mysqli_fetch_array($sqldata)) {
$rows[] = $r;
}
echo json_encode($rows);
}
}
else {echo "{'id':'99'}";}