2014-05-21 48 views
0

我試着開關語句,但還是一樣...現在我選擇了所有選項會$cimb ...誰能幫我讓他們重定向到正確的URL?PHP - 如果別人都不盡如人意

繼波紋管是我的編碼:

$detectpay = mysql_query("select paymethod from themetransaction"); 
       $showdpay = mysql_fetch_array($detectpay); 
       $credit = "Credit Card"; 
       $cimb = "CIMB Clicks"; 
       $may = "Maybank2U"; 
       $paypal = "Paypal"; 
       $public = "Public eBank"; 
       $rhb = "RHB Now"; 
       switch($showdpay['paymethod']) 
        { 
         case $credit: 
          $echo = "<meta http-equiv='refresh' content='5;url=http://www.facebook.com/' />"; 
          break; 
         case $cimb: 
          $echo = "<meta http-equiv='refresh' content='5;url=https://www.cimbclicks.com.my/ibk/' />"; 
          break; 
         case $may: 
          $echo = "<meta http-equiv='refresh' content='5;url=https://www.maybank2u.com.my/mbb/m2u/common/M2ULogin.do?action=Login' />"; 
          break; 
         case $paypal: 
          $echo = "<meta http-equiv='refresh' content='5;url=https://www.paypal.com/my/cgi-bin/webscr?cmd=_login-submit' />"; 
          break; 
         case $public: 
          $echo = "<meta http-equiv='refresh' content='5;url=https://www2.pbebank.com/myIBK/apppbb/servlet/BxxxServlet?RDOName=BxxxAuth&MethodName=login' />"; 
          break; 
         case $rhb: 
          $echo = "<meta http-equiv='refresh' content='5;url=https://logon.rhb.com.my/ />"; 
          break; 
         default: 
          $echo = "none of the above worked..."; 
        } 


       echo $echo; 
+0

你需要使用一個開關statemente有... –

+1

單'='是賦值運算符,雙''==是比較鬆散和三''===是有嚴格的比較。你至少需要比較寬鬆('==')。除此之外,您應該使用switch語句。主要的好處是你只需要寫一次變量名,而不是你的例子中的6次。 –

+0

@馬蒂亞斯如何做switch語句?即時通訊非常新的PHP – user3652484

回答

3

if需求雙等號:==

if($showdpay['paymethod'] == $credit) //and so on... 

但看到你的代碼,我建議使用一個switch聲明。

一點幫助:

你可以從這個重寫代碼:

if($showdpay['paymethod'] == $credit) 
{ 
    echo " <meta http-equiv='refresh' content='5;url=http://www.facebook.com/' />"; 
} 
elseif($showdpay['paymethod'] == $cimb) 
{ 
    echo"<meta http-equiv='refresh' content='5;url=https://www.cimbclicks.com.my/ibk/' />"; 
} 

這樣:

switch($showdpay['paymethod']) 
{ 
    case $credit: 
     $echo = "<meta http-equiv='refresh' content='5;url=http://www.facebook.com/' />"; 
     break; 
    case $cimb: 
     $echo = "<meta http-equiv='refresh' content='5;url=https://www.cimbclicks.com.my/ibk/' />"; 
     break; 
    default: 
     $echo = "none of the above worked..."; 
} 

echo $echo; 
+0

嗨我使用'=='但仍然相同 – user3652484

+0

嗨感謝您的答案〜但所有選項已成爲'$ cimb'選擇任何選擇將去'$ cimb' url – user3652484

+0

任何想法如何做到這一點? – user3652484

0

你跟=使用== assiging比較值

ie if($showdpay['paymethod'] == $credit)

0

使用==進行比較。單個=用於賦值變量。

if($showdpay['paymethod'] = $credit) 

應該是:

if($showdpay['paymethod'] == $credit) 

也能改變你所有的if else塊。

if($showdpay['paymethod'] = $credit)在執行if之前分配$credit to $showdpay['paymethod'],所以PHP現在將其讀取爲if("Credit Card");,它將一如既往地返回true。

編輯:爲您的查詢。

$detectpay = mysql_query("select paymethod from themetransaction"); 

應該是:

$detectpay = mysql_query("select paymethod from themetransaction where paymethod = '".$var."'"); 

其中$var是你在選擇框選擇的一個。如果信用卡是themetransaction表中的第一條記錄,您的代碼將始終獲得信用卡。