如何使用fetch_array数据在php内部编写html?

时间:2013-06-12 03:24:21

标签: php html

我尝试了很多东西,但我不能让选项的值成为数据库中的id而且我不能将选项作为日期和标题从数据库中写出来 我到目前为止这样做,任何帮助将不胜感激。

<select name="agenda "size="10">
            <?php
            global $connection;
            $result = mysql_query("SELECT * FROM agenda where date > now() order by date", $connection);
            $i = 0;
            while ($row = mysql_fetch_array($result) && $i < 20)
                {
                $id = $row['id_agenda'];
                $date = $row['date'];
                $title = $row['title'];
                //here i would like to make an option with 
                //value = id_agenda and write the date_agenda and title_agenda
                //something like this
                //<option value="$row[$id]">$date $title</option>
                $i++;
                }
            ?>
            <option value="Google">meeting 2</option>
        </select>

2 个答案:

答案 0 :(得分:1)

使用:

echo "<option value=\"$id\">$date $title</option>";

答案 1 :(得分:0)

while ($row = mysql_fetch_array($result)) {
    echo "<option value=\"$row[id_agenda]\">$row[date] $row[title]</option>";
}