views:

113

answers:

1

Hi Everyone,

I have this file 'gardens.php', which pulls data from a table called 'generalinfo' and I use fopen to send that data to a file called 'index.html'. Here is the issue, only one option is filled. I have a demo running here Garden Demo <-- this is a new updated page and location, there are more errors than I have locally If anyone could help me fix them Username:stack1 Password:stack1

Is there a better way to achieve what I want to?

Thanks! Always.

GARDENS.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;

?>

INDEX.PHP SNIPPET

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

</form>

CONNECT.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();
?>
+1  A: 

Do you use this snippet in some other PHP file as well? If not you can just integrate into your gardens.php file:

<?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>
Felix Kling
well i am kind of using the index.html file as a template and adding the info from gardens.php to it via fopen
Anders Kitson
i am getting this error on this page http://gardening.andcreate.com/gardens.php which is the one I meant for you to be looking at I mixed some stuff up in my explanation that I have to fix.
Anders Kitson
@Anders Kitson: Well it seems that you have no connection to your DB server. What is inside `connect.php` ?
Felix Kling
I added the code for my connect.php file, I'm not sure what might be causing the same one seems to be working fine on other remote sites I have
Anders Kitson
@Anders Kitson: I removed your username and password from the code. You should never ever post it anywhere! **I SUGGEST TO CHANGE YOUR PASSWORD IMMEDIATELY!!** Anyway, in this file, you are calling `mysql_close()`, which closes the connection to your DB, immediately after you created the connection. Of course, `mysql_query()` has no connection to work with then. Remove this line.
Felix Kling
yikes can't believe I did that. Thanks I'm going to try it without the close now.
Anders Kitson
Ok Awesome Thank you so much for you're help. If you visit http://gardening.andcreate.com/index.php you will notice there are different options now. I wonder how I would achieve this using fopen, or if that way even makes sense at all. Thanks again. I also changed that password now!
Anders Kitson