trying to do what you want is not difficult but it is not a good way to code. It is better to use logic to get things done... also, Personally, I don't like switch statements, why not just keep it simple and use if statement for only 2 conditions.
one other thing, assuming what you did works... you would have for(x>0,x=total,x++) and for(x=total,x>0,x--) ... that first for loop doesn't work... I am assuming you wanted for(x=0, x<total,x++). This is what you should do.
CODE
if ($_GET['date'] == 'asc') { $i = 0; $j = $total }
else if ($_GET['date'] == 'desc') {$i = -$total; $j = $0 }
for ($x=$i;$x<$j;$x++) { do stuff }
If you are actually using the count down counter for something just switch the sign (from neg to pos).
QUOTE(adly3000 @ Feb 22 2006, 09:56 AM)

i'd like to make for loop which dependes on a $_GET variable:
here is my tries:
CODE
if (isset($_GET['date'])
{
switch($_GET['date'])
{
case 'asc':
$exp1 = "$x>0";
$exp2 = "$x=$total";
$condition = '$x++';
break;
case 'desc';
$exp1 = "$x=$total";
$exp2 = "$x>0";
$condition = '$x--';
break;
}
}
then
CODE
for($exp1; $exp2; $condition)
{
//** do something **//
}
that is what i want to do, sure this code is wrong so what is the valid code?!!
Reply