PHP if and CSS Sugestions

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

Post Reply
tragedy
Forum Newbie
Posts: 3
Joined: Sat Feb 27, 2010 3:37 am

PHP if and CSS Sugestions

Post by tragedy »

Hello,

for example

if li id="71" -->

a id="menu" style="background:red;"

How can I do it with PHP

Thank you...
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP if and CSS Sugestions

Post by social_experiment »

If you pass the 'id' in the php, example :

Code: Select all

<?php $id = 1; 
echo "<li id=\"$id\">arbtext</li>";
?>
you could use a case statement. If you use external stylesheets and you want different display for each li element, you will have multiple stylesheets. If you are using an embedded stylesheet (<style></style>), you can let the function create that each time the script is run.

Code: Select all

function changeLiElements($value) {
 switch($value) {
 case(1):
 echo "background-color : red;"
 break;
 case(2):
 echo "background-color : blue;"
 break;
 default:
 echo "background-color : black;"
 break;
 }
} ?>
You then have the function between the <style> tags.

Code: Select all

<style>
 <?php changeLiElements($id); ?>
</style>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
tragedy
Forum Newbie
Posts: 3
Joined: Sat Feb 27, 2010 3:37 am

Re: PHP if and CSS Sugestions

Post by tragedy »

social_experiment wrote:If you pass the 'id' in the php, example :

Code: Select all

<?php $id = 1; 
echo "<li id=\"$id\">arbtext</li>";
?>
you could use a case statement. If you use external stylesheets and you want different display for each li element, you will have multiple stylesheets. If you are using an embedded stylesheet (<style></style>), you can let the function create that each time the script is run.

Code: Select all

function changeLiElements($value) {
 switch($value) {
 case(1):
 echo "background-color : red;"
 break;
 case(2):
 echo "background-color : blue;"
 break;
 default:
 echo "background-color : black;"
 break;
 }
} ?>
You then have the function between the <style> tags.

Code: Select all

<style>
 <?php changeLiElements($id); ?>
</style>

Thanks for responding. But this is not help for me,

Actually I want to change if li id="70" -> a id="23" with CSS (a#23{background:red;})
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP if and CSS Sugestions

Post by social_experiment »

if li id="71" -->
a id="menu" style="background:red;"
Your question was a bit vague. Try javascript.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
tragedy
Forum Newbie
Posts: 3
Joined: Sat Feb 27, 2010 3:37 am

Re: PHP if and CSS Sugestions

Post by tragedy »

social_experiment wrote:
if li id="71" -->
a id="menu" style="background:red;"
Your question was a bit vague. Try javascript.
Yes , u're right. Sorry for my English.

Could you help me, how can i do with js?

Thank you.
Post Reply