[thelist] Logic headache
Paul Roub
paul at roub.net
Mon Nov 11 10:54:01 CST 2002
Two loops, nested. The first counts from 1 to $maxlevels -- the level which
you are excluding at this time.
The inner loop loops through the same list, building the *included* list for
each level.
Something like:
<select name="exclude">
<option value="">All levels</option>
<?php
$maxlevels = 4; // per your example
for ($curlevel = 1; $curlevel <= $maxlevels; ++$curlevel)
{
$leveldesc = "Level $curlevel";
$valuestr = "";
for ($listlevel = 1; $listlevel <= $maxlevels; ++$listlevel)
{
if ($listlevel != $curlevel)
{
if ($valuestr != '')
{
$valuestr .= "|";
}
$valuestr .= "/lvl$listlevel/";
}
}
print "<option value='$valuestr'>$leveldesc</option>\n";
}
?>
</option>
----- Original Message -----
From: "Tony Crockford" <tonyc at boldfish.co.uk>
To: "Thelist at lists. evolt. org" <thelist at lists.evolt.org>
Sent: Monday, November 11, 2002 10:09 AM
Subject: [thelist] Logic headache
> Hi all,
>
> brief explanation:
>
> 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?
>
> I was going to use a while loop or two, but I'm stuck at the point of
> creating the value "string" which should contain all the levels from 1
> to $maxlevels except the current level. which would seem to require some
> sort of conditional "if $thislevel string is" type of approach, but I
> can't get my head round it.
>
> Anyone put me out of my misery?
>
> Thanks
>
> Tony
>
> --
> http://www.maccaws.org/
> [Making A Commercial Case for Adopting Web Standards]
>
> --
> * * Please support the community that supports you. * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>
>
More information about the thelist
mailing list