Page 1 of 1
Html Select Box and php
Posted: Thu Apr 10, 2003 5:33 am
by Nik
Hello, i was wondering if there was a way to give data to an html select box using php and reading that data from a text file
The html syntex for creating such a select box is the following!
What changes must i make in order to make it read data from a php file?
<select name="cd"> <option name="1">One <option name="2">Two </select>
I can also load the contents of the php file to an array using the following
$data=file("data.txt")
Pls help me out with this.....
Posted: Thu Apr 10, 2003 5:54 am
by volka
and what data is in that file?
Posted: Fri Apr 11, 2003 6:59 am
by Coco
dont you need </option> tags?
i normally use a while loop
Code: Select all
$selectfeed = '<select name=monkey>';
while($data=/*datasource*/)
{
$selectfeed .= '<option value="' . $dataї'this'] . '">' . $dataї'that'] . '</option>';
}
$selectfeed .= '</select>';
Posted: Fri Apr 11, 2003 7:16 am
by pootergeist
file.txt
1|one
2|two
etc
$data = explode('|',file('file.txt'));
echo '<select name="selex" />
';
foreach($data as $dataline)
{
echo '<option value="' .$dataline[0]. '">' .$dataline[1]. '</option>
';
}
echo '</select>
';
Posted: Fri Apr 11, 2003 11:12 am
by Nik
Thank u very much guys for your help! Can u pls tell me pootergeist how can i paste this solution to the following cause i didnt fugure it out.
<form action="check.php" method="post">
<table border=1 width=50% align=Center bordercolor=Yellow style='border-style: solid; border-width: 5' background=pics/blue.jpg>
<tr>
<td align=center> <font size=5 color=LightGreen> Τίτλος 1ης ταινίας? </td>
<td align=center> <select name=dvd1> <option name=1> Die Another Day </select></td>
</tr>
<tr>
<td align=center> <font size=5 color=LightGreen> Τίτλος 2ης ταινίας? </td>
<td align=center> <select name=dvd2> <option name=2> Ένα </select></td>
</tr>
<tr>
<td align=center> <font size=5 color=LightGreen> Τίτλος 3ης ταινίας? </td>
<td align=center> <select name=dvd3> <option name=3> Ένα </select></td>
</tr>
<tr>
<td align=center> <font size=5 color=LightGreen> Τίτλος 4ης ταινίας? </td>
<td align=center> <select name=dvd4> <option name=4> Ένα </select></td>
</tr>
<tr>
<td align=center> <font size=5 color=LightGreen> Τίτλος 5ης ταινίας? </td>
<td align=center> <select name=dvd5> <option name=5> Ένα </select></td>
</tr>
</table><br><br>
Aso the txt file is like
text1
text2
text3
with no pipes before it
Thanks again!
Posted: Fri Apr 11, 2003 6:19 pm
by McGruff
It's recommended to htmlspecialchars() php vars added to forms (or before any kind of browser output) - maybe that's been done already.