0

如果唯一纸张显示输入框值设置值但计算多张纸张(如果计算相同的 2 张纸张),则纸张计数创建一个列表框设置选项纸张。

请注意,Paper1 - Paper3 每个都只有一个 Title 值。请注意 Paper4 - Paper5 具有三个不同的 Title 值。我只想显示 Paper1 - Paper3 的文本框和 Paper4 和 Paper5 的列表框。

     mysql fetch record 
      **id       groupoptional        title**
      1           Paper1              Title1
      2           Paper2              Title2
      3           Paper3              Title3
      4           Paper4              Title4
      5           Paper4              Title5
      6           Paper4              Title6
      7           Paper5              Title7
      8           Paper5              Title8
      9           Paper5              Title9

一些例子:

   create html input 1 <input name="Paper1" type="text" value='1'> Title1
   create html input 2 <input name="Paper2" type="text" value='2'> Title2
   create html input 3 <input name="Paper3" type="text" value='3'> Title3

    create html listbox Paper4 -> <select name='paper4'>
                                  <option value="4">Title 4</option>
                                  <option value="5">Title 5</option>
                                  <option value="6">Title 6</option>
                                  </select>

     create html listbox Paper5 -> <select name='paper5'>
                                   <option value="7">Title 7</option>
                                   <option value="8">Title 8</option>
                                   <option value="9">Title 9</option>
                                   </select>
4

1 回答 1

1

虽然很难弄清楚你在问什么,但我认为你想要这样的东西:

$sql = "SELECT id, groupoptional, title FROM tableName";
$results = $db->query($sql);

$newArray = array();

foreach($results as $row)
{
    if(isset($newArray[$row["groupoptional"]]))
    {
        $newArray[$row["groupoptional"]][] = array("id" => $row["id"], "title" => $row["title"]);
    }
    else
    {
        $newArray[$row["groupoptional"]] = array(array("id" => $row["id"], "title" => $row["title"]));
    }
}

foreach($newArray as $key => $value)
{
    if(count($value) > 1)
    {
        echo "<select name='".$key."'>";
        foreach($value as $group)
        {
            echo "<option value='".$group["id"]."'>".$group["title"]."</option>";
        }
        echo "</select>";
    }
    else
    {
        echo "<input type='text' name='".$key."' value='".$value[0]["id"]."'> ".$value[0]["title"];
    }
}
于 2012-09-05T13:17:45.300 回答