TEXT File to COMBO Box, Read Text file and create combo with it - PHP / MySQL Tutorials
 
  Buy Ebooks, Video Games, DVDs, Electronics and more !
Home | Help Forums | Web Design Tutorials | Free Swishmax Downloads Make Money Online Blog . Free Image and Photo Sharing and Hosting

 

 

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

   Free image hosting
   Web Design Pakistan
   Swish Templates
   SWiSH Climax
   Talkfreelance Community
   Template Desire
   Lite boards
   Script Sector
   GimpTalk
   13dots
   Idea Designs
   PHP Cafe
   Sposatoettore
   Free swishmax templates
   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.



© 2002-2005 Flaxweb Network | Article Manager | Gimp Tutorials Library | RAD C++ Library | Free C/C++ Sourcecode |
Sites of interest : Web Design Blog | Swish Templates | Swishmax Ebook | Photoshop Templates | Gimp Tutorials | Text Forum | Make Money Online