Using fopen and str_replace to auto fill a select option
Posted
by Anders Kitson
on Stack Overflow
See other posts from Stack Overflow
or by Anders Kitson
Published on 2010-04-19T16:16:30Z
Indexed on
2010/04/19
17:23 UTC
Read the original article
Hit count: 240
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>
© Stack Overflow or respective owner