Grant Holmes Posted January 16, 2008 Share Posted January 16, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/86362-solved-alternate-row-colors-in-table-new-issue/ Share on other sites More sharing options...
pocobueno1388 Posted January 16, 2008 Share Posted January 16, 2008 You need to use double quotes with your echo. Try <?php //Alternate Row Color if($i % 2) { echo "<TR bgcolor='$DarkRowColor'>"; } else { echo "<TR bgcolor='$LightRowColor'>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86362-solved-alternate-row-colors-in-table-new-issue/#findComment-441276 Share on other sites More sharing options...
nikefido Posted January 16, 2008 Share Posted January 16, 2008 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/86362-solved-alternate-row-colors-in-table-new-issue/#findComment-441283 Share on other sites More sharing options...
cooldude832 Posted January 16, 2008 Share Posted January 16, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86362-solved-alternate-row-colors-in-table-new-issue/#findComment-441284 Share on other sites More sharing options...
Ken2k7 Posted January 16, 2008 Share Posted January 16, 2008 Did you include the config.php file? Quote Link to comment https://forums.phpfreaks.com/topic/86362-solved-alternate-row-colors-in-table-new-issue/#findComment-441287 Share on other sites More sharing options...
pocobueno1388 Posted January 16, 2008 Share Posted January 16, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86362-solved-alternate-row-colors-in-table-new-issue/#findComment-441293 Share on other sites More sharing options...
Grant Holmes Posted January 16, 2008 Author Share Posted January 16, 2008 pocobueno1388, The change in quotes did the trick. thanks all!!! SOLVED Quote Link to comment https://forums.phpfreaks.com/topic/86362-solved-alternate-row-colors-in-table-new-issue/#findComment-441306 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.