<?PHP
$tmp = array_chunk($service_list,3);
foreach($tmp as $k => $v){
echo '<ul class="service_list">';
foreach($v as $row => $list_items)
echo "<li>$list_items[item] </li>";
echo '</ul>';
}
?>
SELECT clients.name,clients.id FROM clients WHERE (SELECT COUNT(*) FROM orders WHERE orders.id_client = clients.id) >3
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chat</title>
</head>
<style>
.msgblock{
width:300px;
background: #CCC;
border-radius: 20px;
margin-top:20px;
padding: 10px;
}
.msgblock>.date{
font-style: italic;
}
.msgblock>.username{
font-weight: bold;
}
.msgblock>.msg{
display: block;
width:100%;
}
button,textarea,label{
display: block;
margin:5px;
}
</style>
<script src="./jquery-3.3.1.min.js"></script>
<script>
//Получаем timestamp последнего сообщения, если нету сообщений то 0 чтобы получить все
function getTimeStamp(){
if($(".msgblock").length == 0)
return 0;
var $msgs = $(".msgblock");
return $($msgs[$msgs.length-1]).data("timestamp");
}
$(document).ready(function(){
//Добавляем сообщение
$("#send").on("click",function(){
$.ajax({
method: "POST",
url: "./handler.php",
data: { userid: $("#userid").val(),msg:$("#msg").val()}
}).done(function(){getMsgAfterTime();});
});
//Таймер на запрос новых сообщений каждую секунду
(function updateData(){
getMsgAfterTime(function(){
setTimeout(updateData,1000);
});
})();
});
//Получение новых сообщение и добавление
function getMsgAfterTime(callback){
$.ajax({
method: "POST",
url: "./handler.php",
data: { timestamp: getTimeStamp()}
})
.done(function( newValue ) {
if(newValue != "")
$("#msgs").append($(newValue));
if(typeof(callback) == "function")
callback();
});
}
</script>
<body>
<div id="msgs">
</div>
<label>UserID<input type="text" id="userid" value="1"></label><br>
<textarea id="msg" cols="30" rows="10"></textarea>
<button id="send">Отправить</button>
</body>
</html>
<?php
define("DB_HOST","localhost");
define("DB_LOGIN","root");
define("DB_PASSWORD","123456");
define("DB_PORT","3306");
define("DB_NAME","testchat");
function getConnection(){
return new mysqli(DB_HOST.":".DB_PORT, DB_LOGIN, DB_PASSWORD, DB_NAME);
}
//Получаем сообщения которые пришли после времени $_POST["timestamp"]
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["timestamp"])){
$con = getConnection();
$sql = "SELECT msg,date,login,UNIX_TIMESTAMP(date) as timestamp FROM msg INNER JOIN users ON msg.user_id=users.id WHERE UNIX_TIMESTAMP(date) > $_POST[timestamp]";
$res = $con->query($sql);
while($msg = $res->fetch_assoc())
echo <<<EOT
<div class="msgblock" data-timestamp='$msg[timestamp]'>
<span class="username">$msg[login]</span>
<span class="date">$msg[date]</span>
<span class="msg">$msg[msg]</span>
</div>
EOT;
$con->close();
}
//Добавляем сообщение
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["userid"]) && isset($_POST["msg"])){
$con = getConnection();
$sql = "INSERT INTO msg(user_id,msg) VALUES('$_POST[userid]','$_POST[msg]')";
$con->query($sql);
$con->close();
}
?>
$(document).ready(function () {
$(".btn").on("click", function () {
$(this).find(".img-animation").css({
"width": "100%",
"height": "100%",
});
var _this = this;
$(this).find(".text-description").fadeIn("slow",function(){
$(_this).find(".img-description").fadeOut("slow");
});
});
});
function iRead(item, options) {
....
this._events_read = [];
this._events_unread = [];
this.on = function(evt,func){
switch(evt){
case "newsRead":
this._events_read.push(func);
break;
case "newsUnread":
this._events_unread.push(func);
break;
}
}
}
iRead.prototype.read = function() {
this.item.addClass('read');
this._events_read.map(function(e){e();});
};
iRead.prototype.unread = function() {
this.item.removeClass('read');
this._events_unread.map(function(e){e();});
};
var s = new iRead();
s.on("newsRead",function(){alert("readed!")});
s.on("newsUnread",function(){alert("unreaded!")});
s.read();//readed
s.unread();//unreaded