Jump to content


Photo

Altering Link Class


  • Please log in to reply
6 replies to this topic

#1 sorensens

sorensens
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 June 2006 - 10:12 PM

Hi ^.^ For some reason my brain's just not computing to do this. Basically what I'm looking for is making it so that "admins" have one color in links while "members" have a different color. This is the code I'm working woth right now:

$query = "select member_status from membership where name = '$member'";
$result = mysql_query($query) or die(mysql_error());

$member_status = mysql_result($result, 0);
if ($member_status=='2') {
// Etc...

Right now I import a CSS/PHP page to change how everything looks and I was hoping to add two classes there to use for how the admin and member links look.

#2 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 28 June 2006 - 10:26 PM

I think you have the idea pretty much.

<?php
// Check to see the status of the user
if($member_status == '2') {
   // User is Admin
   $style = "adminStyle";
} else {
   // User is Not Admin
   $style = "regularStyle";
}

?>

<a class="<?php echo $style;?> href="#""> First Link</a>

So now if your an Admin it will look like
<a class="adminStyle" href="#">First Link</a>
and if your Not an Admin
<a class="regularStyle" href="#">First Link</a>




#3 sorensens

sorensens
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 29 June 2006 - 03:50 AM

[!--quoteo(post=389036:date=Jun 28 2006, 04:26 PM:name=SharkBait)--][div class=\'quotetop\']QUOTE(SharkBait @ Jun 28 2006, 04:26 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I think you have the idea pretty much.

<?php
// Check to see the status of the user
if($member_status == '2') {
   // User is Admin
   $style = "adminStyle";
} else {
   // User is Not Admin
   $style = "regularStyle";
}

?>

<a class="<?php echo $style;?> href="#""> First Link</a>

So now if your an Admin it will look like
<a class="adminStyle" href="#">First Link</a>
and if your Not an Admin
<a class="regularStyle" href="#">First Link</a>
[/quote]


^.^ Thank you for helping. My only problem left now is that my link is being echo'd already from inside the php and I can't figure out how to get it to echo within double quotes.

ex. this is the specific line I'm changing
<a href="viewprofile.php?id='.$id.'" class='.$style.'>'.$name.'</a>  


#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 29 June 2006 - 04:22 AM

[!--quoteo(post=389094:date=Jun 29 2006, 03:50 AM:name=Sorensen)--][div class=\'quotetop\']QUOTE(Sorensen @ Jun 29 2006, 03:50 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
^.^ Thank you for helping. My only problem left now is that my link is being echo'd already from inside the php and I can't figure out how to get it to echo within double quotes.

ex. this is the specific line I'm changing
<a href="viewprofile.php?id='.$id.'" class='.$style.'>'.$name.'</a>  
[/quote]


<a href="viewprofile.php?id='.$id.'" class='.$style.'>'".$name."'</a>
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 sorensens

sorensens
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 29 June 2006 - 05:14 AM

[!--quoteo(post=389097:date=Jun 28 2006, 10:22 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 28 2006, 10:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<a href="viewprofile.php?id='.$id.'" class='.$style.'>'".$name."'</a>
[/quote]

Sorry, what I meant to say was that the link when you view source looks like -

<a href="viewprofile.php?id='.$id.'" class=adminStyle>'.$name.'</a>

So the class isn't working :(

#6 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 29 June 2006 - 07:31 AM

rather than changing all of your links, an easier way would be to change the link class.

eg..

//** Goes inbetween the "head" tags of your document.

echo "<style type=\"text/css\">";
if($member_status == 2)
{
    echo "a:link {}";    //** Starting example, Admin link styles goes here
}else{
    echo "a:link {}";    //** Starting example, User link styles goes here
}
echo "</style>";

OR you could include a different stylesheet. eg, an "extra" one.

hth, Zac.

#7 sorensens

sorensens
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 29 June 2006 - 01:45 PM

[!--quoteo(post=389147:date=Jun 29 2006, 01:31 AM:name=heckenschutze)--][div class=\'quotetop\']QUOTE(heckenschutze @ Jun 29 2006, 01:31 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
rather than changing all of your links, an easier way would be to change the link class.

eg..

//** Goes inbetween the "head" tags of your document.

echo "<style type=\"text/css\">";
if($member_status == 2)
{
    echo "a:link {}";    //** Starting example, Admin link styles goes here
}else{
    echo "a:link {}";    //** Starting example, User link styles goes here
}
echo "</style>";

OR you could include a different stylesheet. eg, an "extra" one.

hth, Zac.
[/quote]

:/ I need to use the link from before though - there's only one link as it's from my usersonline. The style isn't giving me the problem it's applying the style to the link that's not working since I can't just put something like
class=" '.$style.' "





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users