2015-09-17 125 views
1

我有以下代码MySql的PHP选择下拉列表中

echo '<table class="bookings">'; 
while($row = mysql_fetch_array($result)){ 

//set variables for events 
    $id = $row['CourseDateID']; 
    $begin = $row['CourseStartDate']; 
    $end = $row['CourseEndDate']; 
    $title = $row['CourseTitle']; 
    $att = $row['Attendees']; 
    $venue = $row['CourseLocation']; 
    $formatted = date('Y-m-d', strtotime($begin)); 

    echo '<tr>'; 
    echo '<td>' . $formatted . '</td>'; 
    echo '<td>' . $title . '</td>'; 
    echo '<td>' . '<select>' . '<option>' . $att . '</option>' . '</select>' . '</td>'; 
    echo ' ' . '<td>' . '<a href="/cal.php?id=' . $id . '&begin=' . $begin . '&end=' . $end . '&title=' . $title . '&att=' . $att . '&venue=' . $venue . '">Add Bookings to Calendar</a>' . '</td>'; 
    echo '</tr>'; 
} 
    echo '</table>'; 

我想<select>列出与会者作为一个下拉,但ATM它创建了一个<select>箱在而非下拉列表中的所有参加者的姓名。

希望是有道理的。

+0

'$ row ['Attendees']'的内容是什么? – FuzzyTree

+0

是的,$ row ['Attendees']的大小是多少?如果这是一个数组,你将不得不做一些这里描述的内容 - http://stackoverflow.com/questions/23546818/php-foreach-loop-to-populate-dropdown-list-with-values-from-an-array -of-arrays –

+0

对不起@FuzzyTree'$ row ['Attendees']'只是$ row ['Forenames']'&'$ row ['Surname']' 的分组感谢 – webcreator25

回答

0

假设参加者值是一个CSV列表,例如John,Fred,Jane,Mary,你要爆炸的是到一个数组和循环就可以了:

while($row = ...) { 
    ... start table row+select 
    $names = explode(',', $row['Attendees']); 
    foreach($names as $name) { 
     echo "<option>$name</option>" 
    } 
    ... end select + table row 
} 
+0

不欢乐:/ ...参加者是预订姓名和姓氏的分组吗? – webcreator25

+0

那么它是'日期,日期,会议,名称'一堆记录,并且每行都包含一个名称?那么您需要添加更多的逻辑来检测何时在会议之间切换以及适当地开始/结束表格/选择。 –

0

你肯定会需要为ATLEAST一个循环结构,只是一个建议,jQuery的也是特别是如果你需要每个ID的好方法为每个参加者动态地进行。