พอดีมันเข้าแค่เงื่อนไข IF แต่ไม่เข้าเงื่อนไข ELSEIF ครับ รบกวนทีครับ
Code (PHP)
<?php
include 'connect.php';
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
if ($year != "")
{
$data = $db->prepare('SELECT YEAR(start)+543 AS dtYear, COUNT((YEAR(start))+543) AS count_year
FROM tbl_logs
WHERE YEAR(start) = :y
GROUP BY dtYear
HAVING count_year
ORDER BY dtYear DESC');
$data->bindParam(':y',$year);
$data->execute();
while ($rows = $data->fetch(PDO::FETCH_ASSOC))
{
echo $rows['dtYear'].'-'.$rows['count_year'];
}
}
elseif ($month && $year != "")
{
$data1 = $db->prepare('SELECT YEAR(start)+543 AS dtYear, COUNT((YEAR(start))+543) AS count_year
FROM tbl_logs
WHERE YEAR(start) = :y AND MONTH(start) = :m
GROUP BY dtYear
HAVING count_year
ORDER BY dtYear DESC');
$data1->bindParam(':y',$year);
$data1->bindParam(':m',$month);
$data1->execute();
while ($rows1 = $data1->fetch(PDO::FETCH_ASSOC))
{
echo $rows1['dtYear'].'-'.$rows1['count_year'];
}
}
?>
<?php
include 'connect.php';
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
if ($year != "")
{
$data = $db->prepare('SELECT YEAR(start)+543 AS dtYear, COUNT((YEAR(start))+543) AS count_year
FROM tbl_logs
WHERE YEAR(start) = :y
GROUP BY dtYear
HAVING count_year
ORDER BY dtYear DESC');
$data->bindParam(':y',$year);
$data->execute();
while ($rows = $data->fetch(PDO::FETCH_ASSOC))
{
echo $rows['dtYear'].'-'.$rows['count_year'];
}
}
else if ($month != "" && $year != "")
{
$data1 = $db->prepare('SELECT YEAR(start)+543 AS dtYear, COUNT((YEAR(start))+543) AS count_year
FROM tbl_logs
WHERE YEAR(start) = :y AND MONTH(start) = :m
GROUP BY dtYear
HAVING count_year
ORDER BY dtYear DESC');
$data1->bindParam(':y',$year);
$data1->bindParam(':m',$month);
$data1->execute();
while ($rows1 = $data1->fetch(PDO::FETCH_ASSOC))
{
echo $rows1['dtYear'].'-'.$rows1['count_year'];
}
}
else if($day !="" && $month !="" && $year != "")
{
$data1 = $db->prepare('SELECT YEAR(start)+543 AS dtYear, COUNT((YEAR(start))+543) AS count_year
FROM tbl_logs
WHERE YEAR(start) = :y AND MONTH(start) = :m
GROUP BY dtYear
HAVING count_year
ORDER BY dtYear DESC');
$data1->bindParam(':y',$year);
$data1->bindParam(':m',$month);
$data1->execute();
while ($rows1 = $data1->fetch(PDO::FETCH_ASSOC))
{
echo $rows1['dtYear'].'-'.$rows1['count_year'];
}
}
?>