Jump to content

Recommended Posts

YEs, I'm back with another challenge in relation to doing this. This is related to this issue, but new.

 

I'm getting the colors just fine when my code says:

<?php
//Alternate Row Color
if($i % 2) 
	{ 
	echo '<TR bgcolor="silver">';
	} 
else 
	{ 
	echo '<TR bgcolor="#ffffff">';
	}
?>

 

I have a config file that is INCLUDEd on this page with many variables in the page. I added: these lines:

//
//These are the colors that alternate colors in tables
$LightRowColor = "#FFFFFF";
$DarkRowColor = "silver";
//

 

then I changed the code above to:

<?php
//Alternate Row Color
if($i % 2) 
	{ 
	echo '<TR bgcolor="$DarkRowColor">';
	} 
else 
	{ 
	echo '<TR bgcolor="$LightRowColor">';
	}
?>		

 

This way I could go into this one file and change any tables with that include. However, as you have probably guessed, it doesn't work. My rows alternate with Black and Blue. I'm sure its the way I put the variable in the PHP, but don't know what to fix.

 

Help please?

 

run a test to see if the variables are set - you can use "isset" or just echo them out (simply to test that they are being set properly)

 

You might need to declare them as global before you use them.

 

<?php
global $LightRowColor;
global $DarkRowColor;
?>

You need to use double quotes with your echo. Try

 

Not tehcnically double quotes, quotation and escaping is as very "lose" topic in php (or 'lose' for you single quoters) read up on it as you can do it many ways once you find a method comfortable stick to it I like to use double quotes across and singles for mysql values and array keys i.e

<?php 
$day_the_week = "Tuesday";
echo "Welcome: ".$_SESSION['UserData']['Username']." to \"The\" place today is ".$day_the_week.", have a great day.";
?>

 

That is how I like to do things but it isn't the only way to do it.

You need to use double quotes with your echo. Try

 

Not tehcnically double quotes, quotation and escaping is as very "lose" topic in php (or 'lose' for you single quoters) read up on it as you can do it many ways once you find a method comfortable stick to it I like to use double quotes across and singles for mysql values and array keys i.e

<?php 
$day_the_week = "Tuesday";
echo "Welcome: ".$_SESSION['UserData']['Username']." to \"The\" place today is ".$day_the_week.", have a great day.";
?>

 

That is how I like to do things but it isn't the only way to do it.

 

Yes, there are a few ways you can do it. It really doesn't make a difference whether you use concatenation as you did, or if you just use double quotes so PHP doesn't process the line as just a string. It's just personal preference.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.