php中逗号分隔的列表

2021-12-29 00:00:00 php mysql drupal

我正在尝试构建一个由逗号分隔的列表,它应该看起来像这样(绿色、橙色、红色).

I am trying to build a list separated by commas which should look like this (green, orange, red).

$i=0;
$taxonomy = $form_state[values][taxonomy][5];
foreach ($taxonomy as $key => $value){
  $result = db_query("SQL CODE goes here");
  if (mysql_num_rows($result)){     
  while ($i<mysql_num_rows($result)){
    $resultset = db_fetch_array($result);
    $comma_separated = implode(",", $resultset);
    $i++;      
  }
  form_set_error("Date", t("$comma_separated. cannot be booked more than once "));
}

推荐答案

$resultset=array();
while ($data = db_fetch_array($result)) {
    $resultset[] = $data;
}
$comma_separated = implode(",", $resultset);

相关文章