Using the following example:
Is it possible to rewrite this so that $number will equal the correct number of entries that were exploded, regardless of how many there are at the time?
I am trying to work this so that I do not need to go in and edit the variable $number everytime the text file changes.
This snippet is part of a code for filling in an option list (dropdown) and may contain, on any given day, from 1 to 20 entries. Leaving $number equaling 20 outputs a dropdown with (at times) 3 actual entries and 17 blank ones. Which just looks really tacky in my opinion.
Thanks in advance!
IamStang
Code:
$myFile = "optionList.txt";
$myOptions = fopen($myFile, "r");
$lock = flock($myOptions, LOCK_SH);
if ($lock) {
$options_read = fread($myOptions, filesize($myFile));
$lock = flock($myOptions, LOCK_UN); }
fclose($myOptions);
$exp_Options = explode(",", $options_read);
$number = 20;
$x = 0;
while ($x < $number) {
$namenumber = $x + 1;
echo "<option value = '$exp_Options[$x]'>$exp_Options[$x]</option>";
++$x;
}
Is it possible to rewrite this so that $number will equal the correct number of entries that were exploded, regardless of how many there are at the time?
I am trying to work this so that I do not need to go in and edit the variable $number everytime the text file changes.
This snippet is part of a code for filling in an option list (dropdown) and may contain, on any given day, from 1 to 20 entries. Leaving $number equaling 20 outputs a dropdown with (at times) 3 actual entries and 17 blank ones. Which just looks really tacky in my opinion.
Thanks in advance!
IamStang