Here is a function which reads the text file and creates combo in a way it puts each line text as a combo box entry.
so usage of thes function in yoru script will be so simple, because this function requires only two arguments as filename, and object name and returns a combo box. (object name is the combo variable name in html and taht will be recieved in php script)
usage in your script
| CODE | <?
include "db_txt2combo.php"; ...... ...... ......
$mycom = db_txt2combo("test.txt","combo1");
echo $mycom;
//or simply
echo db_txt2combo("test.txt","combo1"); ...... ...... ?>
|
now copy following code and save it as 'db_txt2combo.php' in the same folder where your script is :
| CODE | <?
function db_txt2combo($filename,$cname) {
$arr=file($filename); $ret="<select name='$cname'>"; for($i=0; $i<count($arr); $i++) { $entry=$arr[$i]; $entry = str_replace("\n","",$entry); $entry = str_replace("\r","",$entry); $entry = trim($entry);
$val=$i+1; $ret .= "<option value=$val>$entry</option>"; } $ret .= "</select>"; return $ret; } ?>
|
NOTE : The script which will recieve the form (which contains this combo), will user variable $combo1 and the value of theis variable will be the line number the user selected (as 1 2 3 4 or so so).
I hope it helps much. Post question if any.
Download the attached file contains same example, demonstrated above.
|