WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 8 times)
Viewed : 28894
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  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
Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used.
Categories : HTML and PHP, PHP, Date Time
How to Create a Shoutbox Using PHP & MySQL
Categories : PHP, MySQL, Web Applications, Beginner Guides, HTML and PHP
This PHP function creates dropdown select lists for time and date that you can change, outputs a 14 char MySQL timestamp in a text field
Categories : PHP, MySQL, Java Script, HTML and PHP
If you want to create select buttons featuring current date this example will show you how...
Categories : Date Time, HTML and PHP, PHP
PHP4 HTTP Compression Speeds up the Web
Categories : PHP, Zlib, HTML and PHP, HTTP, Network
XDT Topsite (Gold v1.0)
Categories : Databases, CSS, PHP, HTML and PHP, Sessions
MySQL or SQL Query to XML Output
Categories : PHP, MySQL, XML, Databases
function textwrap will wrap text to any desired width using <BR>\n as the default line break. Default wrap width is 80 columns.
Categories : Strings, HTML and PHP, PHP
Using select multiple with php3
Categories : HTML and PHP, PHP
Freshmeat.net XML-RPC - This class is meant to query Freshmeat for information about registered projects.
Categories : PHP, PHP Classes, XML, Web Services
A PHP useradmin for MySQL. Uploading is easy. The only thing you need is PHP and MySQL installed!
Categories : MySQL, Databases, PHP, HTML and PHP
Simple newsreader script
Categories : PHP, XML, Rich Site Summary (RSS)
This simple PHP script encodes an HTML document so that its contents may be displayed as a web page.
Categories : Complete Programs, HTML and PHP, PHP
Newbie Notes #9 - Hyperlinking a post
Categories : PHP, Java Script, HTML and PHP, Beginner Guides
 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