1

这是一个新手问题...我在 Joomla 3.3 和 chronoforms v5 中有一个最新的表格...当表格加载时,数据库会使用我的数据库中的“面试日期”填充我的第一个选择输入...。效果很好,一旦你选择日期,第二个选择输入填充可用时隙....这里的问题是数据库在数组中的输出方式是

数据->时间->7:00am,7:15am,9:30am

现在,当第二个选择加载时,它会像这样显示 7:00am,7:15am,9:30am....我希望能够使它们成为单独的值而不是一个值...这是我的代码当前用于第二个选择输入的“时间”选项...

    <?php
    $options = array();
    if ( !$form->data['Data'] || count($form->data['Data']) < 1 ) {
      // no result was found
      $options[] = 'Please select a category';
    } else {
      foreach ( $form->data['Data'] as $d ) {
        $options[$d['interviewdate']] = ($d['time']);
      }
    }
    echo json_encode ($options);
    ?>

这可能吗?

4

2 回答 2

1

The structure that is needed to create an options list is like this:

[0] => array ('text' => 'aaa', 'value' => 'xxx'),
[1] => array ( . . .

And your data appears to be be in a nested array like $form->data['Data']['time'] ?

In this case the text and value can probably be the same so the code would be something like this:

<?php
$options = array();
if ( !$form->data['Data']['time'] ) {
  // no result was found
  $options[] = array('text' => 'Please select a category', 'value' => '');
} else {
  $data = explode(',', $form->data['Data']['time']);
  foreach ( $data as $d ) {
    $options[] = array('text' => $d['time'], 'value' => $d['time']);
  }
}
echo json_encode($options);
?>
于 2015-01-08T10:10:54.483 回答
0

如果我没记错的话,你$d['time']持有的值是“7:00am,7:15am,9:30am”。如果是这种情况,那么您可以使用explode(',', $d['time'])which 将为您提供时间数组而不是字符串。

$options = array();
$form = new stdClass();
$form->data['Data'] = array(
    array(
        'interviewdate' => 'date', 'time' => '7:02am,7:25am,9:40am'
    ),
    array(
        'interviewdate' => 'date2', 'time' => '7:05am,7:35am,19:40am'
    )
);
if ( !$form->data['Data'] || count($form->data['Data']) < 1 ) {
    // no result was found
    $options[] = 'Please select a category';
} else {
    foreach ( $form->data['Data'] as $d ) {
       foreach(explode(',', $d['time']) as $time){
          $options[] = array($d['interviewdate'] => $time);
       }
    }
}
echo json_encode ($options);
于 2014-12-23T16:21:17.313 回答