Highlighting a row in a table with many rows

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
ThePHPApprentice
Forum Newbie
Posts: 3
Joined: Thu Apr 01, 2010 8:31 am

Highlighting a row in a table with many rows

Post by ThePHPApprentice »

Hi,

Newbie here.

I am trying to hlighlight a row in a table with many rows using a css class.
As the user click on a team link (left), the stats related to that team bolden (the css class applies). I know I need an if statement of some kind but where in my code and how to set it up...

Any hints? I have created a variable called $sel_stat which contains $_GET values (team_id) for each team.
Here is my code and a picture of the table which is attached.

Code: Select all


<tr>
    	<?php
        	//3. Perform Database Query
			$standing_stat = mysql_query("SELECT * FROM teams", $connection);
			if (!$standing_stat) {
				die("Database connection failed: " . mysql_error());
			}
			//4. Use Returned Data
			echo  "<br />";
			while ($stat = mysql_fetch_array($standing_stat)) {
				echo "<td><a href=\"standings.php?stat=" . urlencode($stat["team_id"]) .
				"\">{$stat["team_name"]}</a></td>";
				
				echo "<td>" . $stat["rank"] . "</td>";
				echo "<td>" . $stat["gp"] . "</td>";
				echo "<td>" . $stat["wins"] . "</td>";
				echo "<td>" . $stat["losses"] . "</td>";
				echo "<td>" . $stat["ties"] . "</td>";
				echo "<td>" . $stat["points"] . "</td>";
				echo "<td>" . $stat["goals_for"] . "</td>";
				echo "<td>" . $stat["goals_against"] . "</td>";
				echo "<td>" . $stat["streak"] . "</td>" .
				"<tr></tr>";
			}
			
		?>
  
    
    
    </tr>


Attachments
table.jpg
table.jpg (64.16 KiB) Viewed 354 times
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Highlighting a row in a table with many rows

Post by pickle »

You need a Javascript solution, so I've moved this to the Javascript forum.

You want to add some Javascript so that whenever the team name is clicked, the relevant row gets a class added.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply