2014-05-19 64 views
0

我有一些代碼顯示組合框。這是現有的代碼。我需要這個組合框填充預定義數組。我無法得到這個工作。有人可以幫忙嗎?這是代碼PHP代碼與數組

我可以看到組合框但它沒有填充數組。我可以在組合框上方的網頁中看到數組爲打印文本。

$array1 = array('One','Two','Three','Four','Five','Six','Seven','Eight'); 
print"<tr>". NEWLINE; 
print"<td class='form-lbl-r'>". $translate->_('Release Name') ." <span class='required'>*</span></td>". NEWLINE; 
print"<td class='form-data-l'><Select Name='Release' maxlength='20' name='rel_name_required' value='". session_validate_form_get_field("rel_name_required"). "'></td>". NEWLINE; 
    foreach($array1 as $Released){ 
    print'<option value="'.$Released.'">'.$Released.'</option>'; 
} 
print'</select>'; 
print"</tr>". NEWLINE; 
+0

你是什麼意思「看到數組作爲印刷文本」?你究竟看到了什麼?你確定這個PHP代碼甚至在運行嗎? –

+1

請勿關閉中選擇標籤............. – Kishore

+0

工作完美。問題是什麼 ? – Ravg

回答

0

只是嘗試:

$array1 = array('One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'); 

echo '<tr>'; 
echo '<td class="form-lbl-r">' . $translate->_('Release Name') . ' <span class="required">*</span></td>'; 
echo '<td class="form-data-l">'; 
    echo '<select name="Release" maxlength="20" name="rel_name_required" value="' . session_validate_form_get_field('rel_name_required') . '">'; 
    foreach ($array1 as $Released) { 
    echo '<option value="' . $Released . '">' . $Released . '</option>'; 
    } 
    echo '</select>'; 
echo '</td>'; 
echo '</tr>'; 
0

<select>需要被後面緊跟着<option>。您的代碼在該行末尾有一個</td>

0

通過我的代碼工作完美...

<?php 
$array1 = array('One','Two','Three','Four','Five','Six','Seven','Eight'); 
print"<tr>"; 
print"<td class='form-data-l'><select Name='Release' maxlength='20' name='rel_name_required' value='foobar'></td>"; 
    foreach($array1 as $Released){ 
    print'<option value="'.$Released.'">'.$Released.'</option>'; 
} 
print'</select>'; 
print"</tr>"; 
?> 
0

這是正確的方式和工作完美:

$array1 = array('One','Two','Three','Four','Five','Six','Seven','Eight'); 
    print "<tr>"; 
    print "<td class='form-lbl-r'>". $translate->_('Release Name') ." <span class='required'>*</span>"; 
     print "<td class='form-data-l'>"; 
       print "<Select Name='Release' maxlength='20' name='rel_name_required' value='". session_validate_form_get_field("rel_name_required"). "'>"; 
        foreach($array1 as $Released){ 
         print'<option value="'.$Released.'">'.$Released.'</option>'; 
        } 
       print "</select>"; 
     print "</td>"; 
    print "</td>"; 
    print "</tr>";