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
Forex Trading Online forex trading platform

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 : 3 of 5 (graded 5 times)
Viewed : 16852
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
PHP alternating the colors of table rows with style.
Categories : PHP, HTML and PHP, CSS
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar



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 function which gets all the data from a webpage into a string, we can perform regular expression functions on that data afterwards to get our desired data.
Categories : PHP, URLs, HTML and PHP
GonxTabs : Create elegant HTML tabs based interface
Categories : Navigation, HTML, HTML and PHP, PHP
Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance.
Categories : HTML, PHP, HTML and PHP, Beginner Guides
Simple script to passing persistent and growing array between recalls of one page (manipulate little stack).
Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables
Complex paging with no resultset limit
Categories : PHP, MySQL, Databases, Output Control, HTML and PHP
Display Slashdot headers on your own site
Categories : HTML and PHP, HTML, PHP
Dynamic Loading of XML array data into ComboBox and Display XML data using PHP + DOM + Javascript.
Categories : PHP, Java Script, DOM XML, XML, Arrays
Dynamically generated pop-ups (Select items)
Categories : PHP, HTML and PHP, MySQL, Databases
This script contains 2 functions: 1 to create html select object based on your own customer date format entry- "M d Y h:i.... etc". The second function processes the select object on submit back to unix time.
Categories : PHP, Calendar, Date Time, HTML and PHP
 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