0

我有这个文件'gardens.php' ,它从一个名为'generalinfo'的表中提取数据,然后我使用 fopen 将该数据发送到一个名为'index.html'的文件中。这是问题,只有一个选项被填写。我在这里运行了一个演示Garden Demo <--这是一个新的更新页面和位置,有比我本地更多的错误如果有人可以帮我修复它们 用户名:stack1 密码:stack1

有没有更好的方法来实现我想要的?

谢谢!总是。

花园.PHP

<?php
    include("connect.php");
    $results = mysql_query("SELECT * FROM generalinfo");

    while($row = mysql_fetch_array($results)){
    $country = $row['country'];
    $province = $row['province'];
    $city = $row['city'];
    $address = $row['address'];


    //echo $country;
    //echo $province;
    //echo $city;
    //echo $address;

}

    $fd = fopen("index.html","r") or die ("Can not fopen the file");
        while ($buf =fgets($fd, 1024)){
            $template .= $buf;
        }

    $template = str_replace("<%country%>",$country,$template);

    echo $template;

?>

索引.PHP 片段

<form name="filter" method="get" action="filter.php">
    <select class="country" name="country">
        <option><%country%></option>
    </select>

</form>

连接.PHP

<?php
mysql_connect("mysql.andcreate.com", "*******", "********")or die("Cannot Connect to DB");
mysql_select_db("gardencollective")or die("cannot select the DB table");
mysql_close();
?>
4

1 回答 1

1

您是否也在其他 PHP 文件中使用此代码段?如果没有,您可以直接集成到您的 gardens.php 文件中:

<?php
    include("connect.php");
    $results = mysql_query("SELECT * FROM generalinfo");
    $infos = array();
    while($row = mysql_fetch_array($results)){
        $infos[] = $row;
    }
?>

<form name="filter" method="get" action="filter.php">
    <select class="country" name="country">
        <?php foreach($infos as $info): ?>
            <option><?php echo $info['country'] ?></option>
        <?php endforeach; ?>
    </select>
</form>
于 2010-04-19T16:23:11.667 回答