newnewbie Posted March 17, 2010 Share Posted March 17, 2010 I am trying to learn how to use a php variable in an html table. Somewhere I read that you can "move in and out of" php code in the if else code, since php can only display a variable that is within php code. My "if else" code is in an html table. I don't get errors, but the button that should be grey (stories) remains blue (and an html rollover). I want the button to be grey (and only grey) if the page title is "My Stories." I hope this explains. I have only included one row of the table. Haven't dont the rest, 'cause I can't get it right! Here is my code: <tr> <td><a href="file:///C|/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/site/stories.php"> <?php $page_title == "My Stories"; // Beginning of if else to set button if($page_title == "My Stories") { ?> <img src="../../_img/buttons/gry_Stories.gif" alt="My Stories"> <?php } else { ?> <img src="../../_img/buttons/blu_Stories.gif" border="0" alt="Stories" name="bAstories" id="bAstories" onMouseOver="MM_swapImage('bAstories','','/_img/buttons/gry_Stories.gif',1)" onMouseOut="MM_swapImgRestore()"/></a></td> </tr> </table> </div> </body> </html> <?php } ?> Thanks in advance and pardon my ineptness! Link to comment https://forums.phpfreaks.com/topic/195621-php-if-then-with-a-variable-in-an-html-table/ Share on other sites More sharing options...
schilly Posted March 17, 2010 Share Posted March 17, 2010 you want to do $page_title = "My Stories"; = is for assignment. == is for comparison. Link to comment https://forums.phpfreaks.com/topic/195621-php-if-then-with-a-variable-in-an-html-table/#findComment-1027859 Share on other sites More sharing options...
newnewbie Posted March 18, 2010 Author Share Posted March 18, 2010 Fantastic! I knew I didn't quite get the difference between = and == . Many thanks. (PS I like your tage line about the DAMN semicolon...guess I need one about == ! Link to comment https://forums.phpfreaks.com/topic/195621-php-if-then-with-a-variable-in-an-html-table/#findComment-1028120 Share on other sites More sharing options...
schilly Posted March 18, 2010 Share Posted March 18, 2010 you can look at the php manual for assignment operators. http://www.php.net/manual/en/language.operators.php Link to comment https://forums.phpfreaks.com/topic/195621-php-if-then-with-a-variable-in-an-html-table/#findComment-1028170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.