2016-11-03 17 views
0

我剛剛開始在php中學習一些內容和代碼,並在回聲中取消註釋php代碼時出現問題。我希望你能幫助我。在回聲中取消註釋php/html語句

這裏是我的形式,我不能處理的片段..

echo ' <div class="form-group">'; 
 
echo '  <label class="col-md-3 col-xs-12 control-label" for="textinput">vehicle <span class="required">*</span></label>'; 
 
echo '  <div class="col-md-6 col-xs-12">'; 
 
echo '   <label class="radio-inline">'; 
 
echo '   <input type="radio" name="type" id="radio3" value="car"' . if (isset($_GET['id'])) {echo $row->type == "car" ? 'checked="checked"' : "";}.'> car <span class="required">*</span>'; 
 
echo '   </label>'; 
 
echo '   <label class="radio-inline">'; 
 
echo '   <input type="radio" name="type" id="radio4" value="plane"' .if (isset($_GET['id'])) {echo $row->type == "plane" ? 'checked="checked"' : "";}.'> plane <span class="required">*</span>'; 
 
echo '   </label>'; 
 
echo '  </div>'; 
 
echo ' </div>';

我知道,if子句是不正確的。它一定是這樣的,對吧?

echo (isset($_GET['id'])) ? 'car' : 'not car'); 

但我不知道如何轉換我的isset與這個例子._。

感謝您的幫助!

+1

'回聲「東西」。 (isset($ var)?'更多東西':'其他東西')。''東西';' – Federkun

回答

0

這是你在找什麼:

echo ' <input type="radio" name="type" id="radio3" value="car"' . (isset($_GET['id']))?($row->type == "car" ? 'checked="checked"' : "") : "" .'> car <span class="required">*</span>'; 
echo ' <input type="radio" name="type" id="radio4" value="plane"' .(isset($_GET['id']))?($row->type == "plane" ? 'checked="checked"' : "") : "".'> plane <span class="required">*</span>'; 

爲了使你的代碼更易讀,你應該這樣做:

<?php 
?> 
<div class="form-group"> 
    <label class="col-md-3 col-xs-12 control-label" for="textinput">vehicle <span class="required">*</span></label> 
    <div class="col-md-6 col-xs-12"> 
     <label class="radio-inline"> 
      <input type="radio" name="type" id="radio3" value="car" <?php echo (isset($_GET['id']))?($row->type == "car" ? 'checked="checked"' : "") : "" ?> > car <span class="required">*</span> 
     </label> 
     <label class="radio-inline"> 
      <input type="radio" name="type" id="radio4" value="plane" <?php echo (isset($_GET['id']))?($row->type == "plane" ? 'checked="checked"' : "") : "" ?> > plane <span class="required">*</span> 
     </label> 
    </div> 
</div> 
+0

非常感謝你! – robsn84