Page 1 of 1

a better way?

Posted: Thu Jan 05, 2006 2:58 pm
by C_Calav
any better way to do this? this is just a little bit there are 20 of these.. thanks!

Code: Select all

if($pageis =="alc_sum_01")
   {
    print('<li><a href="/alc_sum_01.php" id="current">1</a></li>');
   }
  else
   {
    print('<li><a href="/alc_sum_01.php">1</a></li>');
   }
 if($pageis =="alc_sum_02")
   {
    print('<li><a href="/alc_sum_02.php"  id="current">2</a></li>');
   }
  else
   {
    print('<li><a href="/alc_sum_02.php">2</a></li>');
   }
 if($pageis =="alc_sum_03")
   {
    print('<li><a href="/alc_sum_03.php" id="current">3</a></li>');
   }
  else
   {
    print('<li><a href="/alc_sum_03.php">3</a></li>');
   }

Posted: Thu Jan 05, 2006 3:02 pm
by hawleyjr
Something like this:

Code: Select all

for($x = 1; $x<20;$x++){
echo '<li><a href="/alc_sum_' . $x . '.php"' . ($pageis =='alc_sum_' . $x ?' id="current':'') . '>' . $x . '</a></li>';
}

Edit: If you do it this way. you'll have to add a zero before the x variable in the php file name.

Posted: Thu Jan 05, 2006 3:17 pm
by C_Calav
thanks very much hawleyjr,

that seems to be what i am looking for.. just gotta tweak it a bit!

cheers

Posted: Fri Jan 06, 2006 5:55 am
by Jenk
FYI; for arbitrary lists, switch / case may be what you are looking for. Though this particular case is made easy because all the names of the files/links are the same, with an incremental suffix :)