Home | Help Forums | Web Design Tutorials | Free Swishmax Downloads | All Downloads

 

 

Company

Home

Nework Details

Tutorials

SWiSH 2

SWiSHMax

Flash MX

PHP & MySQL

HTML / JScript

Adobe Photoshop

Corel Draw

Gimp

Miscellaneous

Downloads

Templates

Plugins

Fonts

Wallpapers

Free Images

Scripts and Codes

Products

E-Books

SWiSH BB

SWiSH Templates

SWiSH-DB Newsletter
Subscribe to our newsletter : GO
  Partners / Affiliates

   Swish Templates
   SWiSH Climax
   GimpTalk
   Idea Designs
   Sposatoettore
   Try Acai Berry Diet
   Download Free Ringtones
   Swishzone

Manage your site with Flax Article Content Management System
TEXT File to COMBO Box, Read Text file and create combo with it
Category : PHP / MySQL | Level : Beginner | Language : English
Ask Question | Read Comments | Post tutorial | Previous | Next

Web www.swish-db.com

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.



All rights reserved - swish-db.com