저는 AJAX를 처음 접했고 배열을 얻는 방법을 모릅니다. 실시간으로 AJAX로 알림 막대를 자동으로 업데이트하려고합니다. 이것은 내가에만 카운트 AJAX 작업 얻을 경우/AJAXAJAX는 여러 배열에서 PHP 출력을 얻습니다.
$sql=mysql_query("select * from $tableName where is_read=0");
$comment_count=mysql_num_rows($sql);
$comm_array = array('count' => $comment_count);
//first output need for get number of notications
echo json_encode($comm_array);
$listsql=mysql_query("select * from notification order by execute_at desc");
while($rowsmall=mysql_fetch_array($listsql))
{
$n_id=$rowsmall['notification_id'];
$date=date("Y-m-d H:i:s", strtotime($rowsmall["execute_at"]));
$command=$rowsmall['command'];
$server=$rowsmall['hostname'];
$status=$rowsmall['status'];
$variable[] = array('data' => "$date",
'command' => "$command",
'server' => "$server",
'status' => "$status");
if($rowsmall['is_read'] == 0)
{
//this was just a try for get with different colors the unread notification
//second output - get notification from mysql
echo json_encode($variable);
}
else
{
//this was just a try for get with different colors the read notification
//second output - get notification from mysql
echo json_encode($variable);
}
}
을 그냥 풍선의 수를 업데이트하고있어 경우에 나는 일을했을하지만 PHP와 MySQL의에서 또한 메시지를받을 수 없습니다 하지만 AJAX를 PHP로 사용하는 방법과 루프를 얻는 방법을 알지 못합니다.
<script>
$(document).ready(function() {
setInterval("ajaxcall()",2000);
});
function ajaxcall() {
//-----------------------------------------------------------------------
// 2) Send a http request with AJAX http://api.jquery.com/jQuery.ajax/
//-----------------------------------------------------------------------
$.ajax({
type: "GET",
url: '/notifications/api.php', //the script to call to get data
success: function(response){ //on recieve of reply
json_object = JSON.parse(response)
var count = json_object.count;
var date = json_object.notifications.data;
var server = json_object.notifications.server;
var command = json_object.notifications.command;
var status = json_object.notifications.status;
//--------------------------------------------------------------------
// 3) Update html content
//--------------------------------------------------------------------
$('#mes').html(count); //Set output element html
$('#not_read').html("Date: "+date+" Host: "+server+" Command: "+command+" Status: "+status);
//recommend reading up on jquery selectors they are awesome
// http://api.jquery.com/category/selectors/
}
});
}
</script>
이것은 내가하고 싶은 것입니다. 빨간색으로 작동하는 알림 수는 있지만 둘 다 작동하는 방법을 알지 못합니다. IMAGE HOW LOOK IN WEB
[mysql_'] (http://stackoverflow.com/questions/12859942/why-shouldnt-i-ex-mysql-functions-in-php) 새 코드에서 데이터베이스 확장자를 사용할 때마다 * * [새끼 고양이는 세계 어딘가에서 교살 된 상태입니다.] (http://bb.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg) ** 그것은 더 이상 사용되지 않으며 수년 동안 PHP7에서 영원히 사라졌습니다. PHP를 배우려는 분이라면'PDO' 또는'mysqli' 데이터베이스 확장과 prepared statement를 배우는 데 많은 시간을 할애하십시오. [여기에서 시작] (http://php.net/manual/en/book.pdo.php) – RiggsFolly