<?
//------------------------------------------------------------------------------------------------------------------//
//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>
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 < $num_elmnts_array; $counter++){
$your_menu .= "<option value=\"$your_variable\">$your_array[$counter]
</option>";
$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?