Jump to content

Recommended Posts

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>";

Link to comment
https://forums.phpfreaks.com/topic/144429-solved-help-with-css-inside-php/
Share on other sites

<?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"); ?>

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

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?

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.