作者Peruheru (還在想)
看板Web_Design
標題Re: [問題] PHP syntax error方面問題
時間Thu Dec 18 11:55:46 2014
※ 引述《godshane (小粉紅)》之銘言:
: 我剛剛在執行if else 語句時
: 一直出現
: Parse error: syntax error, unexpected T_ELSE
: 這個問題
: 以下是我的原始碼
: <td>
: <div class="name">
: <span class="ts">
: <?php
: if($row_rscardoc['position_firemember']=="小隊長")
: {echo 小隊長;}?>
→{echo "小隊長";}?>
: </span>
: <?php else($row_rscardoc['position_firemember']!="小隊長")
→<?php else if($row_rscardoc['position_firemember'] != "小隊長")
: {echo $row_rscardoc['position_firemember'] $row_rscardoc['username'];}?>
→{echo $row_rscardoc['position_firemember'] . $row_rscardoc['username'];}?>
: </div></td>
: 我怎麼找都找不出我錯哪裡
: 可以麻煩各位大大幫幫我嗎 Orz~c=3
另外我覺得
<?php 以及 ?> 這個表示php程式碼的開始與結束符號
不要跟程式碼寫在同一行的話,會比較容易判讀,至少對初學者來說
除非是
<?php = $var ?> 這種東西不需要拆成多行寫(等於 <?php echo $var; ?>)
另外,有PHP版喔
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.134.18.8
※ 文章網址: http://www.ptt.cc/bbs/Web_Design/M.1418874948.A.E47.html
※ 編輯: Peruheru (220.134.18.8), 12/18/2014 12:07:41
推 godshane: 我其實之前有換過elseif 但沒有用 結果我參考你的用法 12/18 12:26
→ godshane: 就可以執行了 應該跟字串的使用方式有關係 謝謝你!! 12/18 12:26
→ Peruheru: 以這個案例來說,其實你根本不需要為else下條件 12/18 12:33
推 godshane: 對.....我腦充血 12/18 14:33