[thelist] Logic headache
R.Livsey
R.Livsey at cache-22.co.uk
Mon Nov 11 09:50:01 CST 2002
> I'm building a select list in PHP, to exclude certain
> directories from a search (with Ht://dig).
>
> The structure is like this:
> <select name="exclude">
> <option value="">All levels</option>
> <option value="/lv2/|/lv3/|/lv4/">Level 1</option>
> <option value="/lv1/|/lv3/|/lv4/">Level 2</option>
> <option value="/lv1/|/lv2/|/lv4/">Level 3</option>
> <option value="/lv1/|/lv2/|/lv3/">Level 4</option>
> </select>
>
> for four levels, where the option value should be all lv's
> except the current option level.
>
> I have a variable $maxlevels to count up to however many
> levels are required and I want to make this select list work
> based on the value of $maxlevels.
>
> How would you approach the building of the list?
>
> Thanks
>
> Tony
Untested but should do the trick.
Note that is probably not the most efficient way of doing it!
<?php
$select =<<<EOD
<select name="exclude">
<option value="">All levels</option>
EOD;
for ($i=1; $i<=$maxLevels; $i++)
{
$levels = '';
for ($j=1; $j<=$maxLevels; $j++)
{
if ($i!=$j)
{
$levels .= "/lv$j/";
if ($j!=$maxLevels)
$levels .= '|';
}
}
$select .=<<<EOD
<option value="$levels">Level $i</option>
EOD;
}
$select .= "</select>":
echo $select;
?>
hth
--
R.Livsey
Incutio Web Developer
[ PHP | Perl | Java | C# ]
w : www.cache-22.co.uk
/ www.incutio.com
More information about the thelist
mailing list