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
PHP Web Logs (BLogs)
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
Submit Site
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 3 times)
Viewed : 14623
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
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
a function that builds an HTML select list from any mysql table.
Categories : PHP, MySQL, HTML and PHP
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
Constantly refresh your PHP/HTML page data.
Categories : PHP, HTML and PHP, Sybase
Select with current month
Categories : PHP, HTML and PHP, Date Time, Arrays
Calendar using Date function
Categories : HTML and PHP, PHP, Date Time, Calendar
PageRank Display
Categories : Search Engines, HTML and PHP, PHP
PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
PHP4 session helper HTML file.
Categories : PHP, Java Script, HTML and PHP, Sessions
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
XPath for PHP without the DOM XML extension
Categories : DOM XML, XML, XSLT, PHP Classes, PHP
Dynamic Calender in PHP, Javascript and HTML.
Categories : PHP, Java Script, HTML and PHP, Calendar
RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS)
 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