Есть код php - с выводом лайков от пользователей. Как сделать так, чтобы когда было 0 лайков, этот 0 скрывался и показывалась цифра, тогда когда значение идет уже от 1 ( единицы )?
Вот сам код
<?php
class like extends db_connect {
private $TEXT = 0;
public $app = 0;
public function __construct($dbo = NULL, $TEXT = 0, $app = 0)
{
parent::__construct($dbo);
$this->TEXT = $TEXT;
$this->app = $app;
}
public function Count($ask_id)
{
$data = array("to_ask_id" => $ask_id);
$stmt = $this->db->prepare("SELECT id FROM ask_like WHERE to_ask_id=(:to_ask_id)");
$stmt->execute($data);
return $stmt->rowCount();
}
public function CountByHash($ask_hash)
{
$stmt = $this->db->prepare("SELECT id FROM ask_like WHERE to_ask_hash=(:to_ask_hash)");
$stmt->bindParam(":to_ask_hash", $ask_hash, PDO::PARAM_STR);
$stmt->execute();
return $stmt->rowCount();
}
public function AddLike($user,$ask_id,$from_id)
{
$ask = new ask($this->db);
$answer = $ask->Data($user,$ask_id);
unset($ask);
if (count($answer) > 0)
{
if ($answer['answer'] > '')
{
$data = array("to_ask_id" => $answer['id'], "from_user_id" => $from_id);
$sth = $this->db->prepare("SELECT id FROM ask_like WHERE to_ask_id=(:to_ask_id) AND from_user_id=(:from_user_id)");
$sth->execute($data);
if ($sth->rowCount() > 0)
{
while ($row = $sth->fetch())
{
$index = $row['id'];
$this->db->exec("DELETE FROM ask_like WHERE id='{$index}'");
if ($from_id != $answer['to_id'])
{
// Category 1 - LIKE
//
$this->app->NotifyRemove(1, $row['id']);
$addon = new addon(0);
$rating = $addon->GetRating($answer['to_id']);
$rating--;
$addon->SetRating($answer['to_id'],$rating);
unset($addon);
}
}
}
else
{
$data = array("to_ask_id" => $answer['id'], "to_ask_hash" => $answer['ask_hash'], "from_user_id" => $from_id, "to_user_id" => $answer['to_id'], "time" => time());
$sth = $this->db->prepare("INSERT INTO ask_like (to_ask_id, from_user_id, to_user_id, to_ask_hash, time) value (:to_ask_id, :from_user_id, :to_user_id, :to_ask_hash, :time)");
$sth->execute($data);
if ($from_id != $answer['to_id'])
{
//
// Category 1 - LIKE
//
$this->app->NotifyAdd($answer['to_id'], 1, $this->db->lastInsertId());
$addon = new addon(0);
$rating = $addon->GetRating($answer['to_id']);
$rating++;
$addon->SetRating($answer['to_id'],$rating);
unset($addon);
}
}
}
}
}
}
?>