WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : On-the-fly drop down menu from a txt or xml file
Categories : PHP, XML, HTML and PHP Click here to Update Your Picture
Eddy DeCoste
Date : Jan 10th 2001
Grade : 2 of 5 (graded 6 times)
Viewed : 19821
File : dropdown_menu_from_file.php
Images : No Images for this code example.
Search : More code by Eddy DeCoste
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?
//------------------------------------------------------------------------------------------------------------------//
//GMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGMEGME//
//-----------------------------------------------------------------------------------------------------------------//
//
//
//        Description: This script will read in a plain file (ex: txt or xml) and //
//         create and populate a dropdown list/menu. The script examines //
//         a text file, creates an array (elements are seperated by a //
// hard return "\n", then empties the elements into a dropdown //
//
menu. //
//
//
//----------------------------------------------------------------------------------------------------------------//
//
//
//        Useage Example: We had a client who wanted many dropdown list ranging //
//                 in size from 50 elements to 3026+. We didn't feel like //
// retyping all those elements. Through this script we //
// were able to create on-the-fly menus that are easily //
//
edited. //
//
//
//--------------------------------------------------------------------------------------------------------------//
//QTIPQTIPQTIPQTIPQTIPQIPQTIPQTIPQTIPQTIPQTIPQTIPQTIPQTIPQTIPQTIPQTIPQTIPQT//
//--------------------------------------------------------------------------------------------------------------//

//var to hold list location (substitute your own file name and text file)
$your_file = "test.xml";

        //open the file
        $read_your_file = @fopen($your_file, "r") or die ("Couldn't Access $your_file");

        //create a variable to hold the contents of the file
        $contents_your_file = fread($read_your_file, filesize($your_file));
        
        //array of file contents
        $your_array = explode("\n",$contents_your_file);

        //close the file
        fclose($read_your_file);

        //counts the number elements in the property_categories array
        $num_elmnts_array = count($your_array) ;

//elements in the drop down list
//$drop_elmnts = 0;

//begin creating your dropdown menu...
$your_menu = "<select name=\"you_make_a_name\">";        
        //For loop to begin
        for($counter = 0; $counter < $num_elmnts_array; $counter++){
         $your_menu .= "<option value=\"$your_variable\">$your_array[$counter]
</option>";
                $counter++;
        }
//end select menu
$your_menu .= "</select>";
?>
<html>
<head>
<title>Drop Down Menu Generated From a File | GME & Q-tip</title>
</head>
<body>

<p><b>Your Menu</b><br>
<? echo "$your_menu"; ?>

</body>
</html>



PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
Upload images restricted by pixel size (Picture width and Picture Height)
Categories : PHP, HTML and PHP, Graphics
phpEasyMail: An easy way to send data from HTML-forms via EMail.
Categories : Email, HTML and PHP, Complete Programs, PHP
Vote-Poll script that has a wrapper class that allows the user to create multiple polls on the same page with little trouble.
Categories : PHP, PHP Classes, HTML and PHP
PHP Tester - Lets you test php code from a browser.
Categories : PHP, HTML and PHP, Testing
Open directory and File download
Categories : PHP, Filesystem, Directories, HTML and PHP
RSS parser using PHP5 and simpleXML
Categories : Rich Site Summary (RSS), PHP, XML
Website Engine
Categories : PHP, HTML and PHP, Templates
Validator 98 - a PHP-script to generate form-validation-code in JavaScript.
Categories : Complete Programs, Java Script, PHP, HTML and PHP
MySQL to XML.
Categories : MySQL, XML, PHP
Dynamic form field
Categories : PHP, HTML and PHP, Form Processing
CSS style switcher
Categories : PHP, CSS, HTML and PHP, Arrays, Sessions
Functions for loading images into a MySQL database and displaying them.
Categories : Graphics, HTML and PHP, MySQL, PHP, Databases
dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL
PHP alternating the colors of table rows with style.
Categories : PHP, HTML and PHP, CSS
 Bill Coker wrote : 505
For some reason it only counts every other entry in the .txt file 

1
not 2
3
not 4
5
not 6

Is there something that I am missing?
 
 mike nilsson wrote : 729
    for($counter = 0; $counter &lt; $num_elmnts_array; $counter++){

that line should look like this

    for($counter = 0; $counter &lt; $num_elmnts_array;){

otherwise it adds 2 times in the counter.
Otherwise, this is what I was looking for, thanks
 
 eddy decoste wrote : 730
Sorry, I made a mistake :(

Original Code:
//For loop to begin 
    for($counter = 0; $counter &lt; $num_elmnts_array; $counter++){ 
       $your_menu .= "&lt;option value=\"$your_variable\"&gt;$your_array[$counter] 
&lt;/option&gt;"; 
        $counter++; 
    
For this to work properly, you are right you must either remove the incrementing of the $counter in the for loop conditionals or at the end of the for loop. Remove one of them and this should work properly.

I have written a more advanced version of this using a mysql database and PHP classes. 

If your interested email me :)
 
 Marcel Smeets wrote : 1750
I am interested in the mysql / php code you wrote. Leave a mail adres please where I can reach you?
 
 eddy decoste wrote :1751
ezekiel61 at hotmail.com