PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Thu Jan 05, 2006 2:58 pm
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>');
}
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Jan 05, 2006 3:02 pm
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.
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Thu Jan 05, 2006 3:17 pm
thanks very much hawleyjr,
that seems to be what i am looking for.. just gotta tweak it a bit!
cheers
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Fri Jan 06, 2006 5:55 am
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