CyberShot Posted February 9, 2009 Share Posted February 9, 2009 I am following a tutorial and I can not figure out why my css class isn't working. I have class set to make a link bold when you select it. but it doesn't work for me. $subject_set = get_all_subjects(); while($subject = mysql_fetch_array($subject_set)) { echo "<li"; if($subject["id"] == $sel_subj) { echo "class=\"selected\""; } echo "><a href=\"content.php?subj=" . urlencode($subject["id"]) . "\"> {$subject["menu_name"]} </a></li>"; Quote Link to comment https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/ Share on other sites More sharing options...
Philip Posted February 9, 2009 Share Posted February 9, 2009 Where is this coming from "$sel_subj"? Quote Link to comment https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/#findComment-757894 Share on other sites More sharing options...
CyberShot Posted February 9, 2009 Author Share Posted February 9, 2009 <?php require_once("includes/functions.php") ?> <?php require_once("includes/connection.php") ?> <?php if(isset($_GET['subj'])) { $sel_subj = $_GET['subj']; $sel_page = ""; } elseif(isset($_GET['page'])){ $sel_subj = ""; $sel_page = $_GET['page']; } else { $sel_page = ""; $sel_subj = ""; } ?> <?php include("includes/header.php"); ?> <table cellpadding="0" cellspacing="0" id="structure"> <tr> <td id="navigation"> <ul class="subjects"> <?php // 4. Use returned data $subject_set = get_all_subjects(); while($subject = mysql_fetch_array($subject_set)) { echo "<li"; if($subject["id"] == $sel_subj) { echo "class=\"selected\""; } echo "><a href=\"content.php?subj=" . urlencode($subject["id"]) . "\"> {$subject["menu_name"]} </a></li>"; $page_set = get_pages_for_subjects($subject["id"]); // 4. Use returned data echo "<ul class=\"pages\">"; while($page = mysql_fetch_array($page_set)) { echo "<li"; if($page["id"] == $sel_page) { echo "class=\"selected\""; } echo "><a href=\"content.php?page=" . urlencode($page["id"]) ."\"> {$page["menu_name"]}</a> </li>"; } echo "</ul>"; } ?> </ul> </td> <td id="page"> <h2>Content Area</h2> <?php echo $sel_subj; echo $sel_page; ?> </td> </tr> </table> <?php require("includes/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/#findComment-757899 Share on other sites More sharing options...
Philip Posted February 9, 2009 Share Posted February 9, 2009 When looking at the source do you see the class="selected" ? Try this: echo "<li"; if($subject["id"] == $sel_subj) { echo " class=\"selected\""; } echo "><a href=\"content.php?subj=" . urlencode($subject["id"]) . "\"> {$subject["menu_name"]} </a></li>"; If that doesn't work, do this: if($subject["id"] == $sel_subj) { echo " class=\"selected\""; } echo "><a href=\"content.php?subj=" . urlencode($subject["id"]) . "\"> {$subject["menu_name"]} </a>"; echo " subjID: ".$subject["id"]." - getID: ".$sel_subj."</li>"; // debugging Quote Link to comment https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/#findComment-757907 Share on other sites More sharing options...
CyberShot Posted February 9, 2009 Author Share Posted February 9, 2009 I may have been staring at this code for to long. I don't see a difference. What do you mean "Do you see the class="selected" "? Quote Link to comment https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/#findComment-757910 Share on other sites More sharing options...
CyberShot Posted February 9, 2009 Author Share Posted February 9, 2009 Thank you very much. I spotted it. I didn't think the space after the quote on the echo " class=\"selected\" would make a difference. It actually fixed three problems I was having. So you fixed three in one, Nice shot.. Thanks for your help. I appreciate it. Now can you tell me why adding a space after a quote fixed the problem? Quote Link to comment https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/#findComment-757913 Share on other sites More sharing options...
Philip Posted February 9, 2009 Share Posted February 9, 2009 Because when it printed, it would print <liclass="selected" compared to: <li class="selected" Quote Link to comment https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/#findComment-757918 Share on other sites More sharing options...
CyberShot Posted February 9, 2009 Author Share Posted February 9, 2009 Oh! I get it! Wow! I never would have spotted that. I knew about spacing from concatinating (spell check) things, but I didn't have any idea that was what was going on here. Thanks for that. That info should come in handy in the future Quote Link to comment https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/#findComment-757921 Share on other sites More sharing options...
Philip Posted February 9, 2009 Share Posted February 9, 2009 Yup, whenever you come across that, take a look at your html source code when viewing the page. You'll notice it pretty quick Quote Link to comment https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/#findComment-757922 Share on other sites More sharing options...
CyberShot Posted February 9, 2009 Author Share Posted February 9, 2009 didn't even think to view the source code of the page. Another great idea. Wow, you are just batting them out of the park tonight! LOL Quote Link to comment https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/#findComment-757924 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.