得到一個表格,顯示每個季度的值。If Elseif Else in PHP based on MYSQL query results
+--------------+-------------------+ | Quarter | Value | +--------------+-------------------+ |2012.Q4 |17000 | |2013.Q1 |18000 | |2013.Q2 |19000 |x |2013.Q3 |26600 |x +--------------+-------------------+
得到一個mysql查詢來計算最後兩行之間的差異。
MySQL的這個例子的結果給出:7600
我想說明根據結果的圖標(根據fontawesome的字體圖標)
If the result > 0 , I want to show the result with icon-caret-up
If the result = 0 , I want to show the result with icon-caret-right
If the result < 0 , I want to show the result with icon-caret-down
所以我加了下面的PHP代碼:
<?php
$reponse=mysql_query("My SQL Query");
if ($reponse > 0) {
echo "<h1 class=\"uk-text-center uk-margin-bottom-remove\">".(mysql_result($reponse, 0))."<i class=\"uk-icon-caret-up\"></i></h1>";
}
elseif ($reponse == 0) {
echo "<h1 class=\"uk-text-center uk-margin-bottom-remove\">".(mysql_result($reponse, 0))."<i class=\"uk-icon-caret-up\"></i></h1>";
}
else {
echo "<h1 class=\"uk-text-center uk-margin-bottom-remove\">".(mysql_result($reponse, 0))."<i class=\"uk-icon-caret-down\"></i></h1>";
}
?>
無論結果如何,即使它是一個負數或等於零,我只拿到了第一選擇顯示圖標,脫字了。
任何想法,我是一個PHP新手。
我提前感謝你。
問候。
它像一個魅力工作。順便說一句,非常感謝您的建議,我是一個PHP新手,所以我正在學習基本概念,即使它已被棄用。這只是切換到PDO和PHP框架之前的第一步。再次,非常感謝所有。問候! – Jays
不客氣 - 祝您好運! – Jessica