Row highlighting...

Hey guys,
I got a form with a set of options in a drop down box

[code]
Name:

Jr.High High School College [/code]

I fetch all the data from the mysql table into another page.The table is as follows:

name school Age
John Jr. High 9
Lilly College 19
Adam High School 14
Jake College 21

Is it possible to highlight the entire row with colors depending on the user’s name?

For example i want John’s row in green, Jake’s row in yellow etc…

If any other information i need to provide please let me know :slight_smile:

Hi there,

You can use a condition statement to check the name that is returned and change the background color of the row as accordingly. Look at my example below:

[php]
echo “

”;

while($row = mysql_fetch_assoc($result))
{
if($row[‘name’] == ‘John’;
{
$bgcolor = “#00FF00”;
}
else
{
$bgcolor = “#FFFFFF”;
}

 echo "<tr bgcolor='$bgcolor'><td>$row[name]</td><td>$row[education]</td><td>$row[age]</td></tr>";

}

echo “</table”;[/php]

As you can see, once the condition statement checks the name field of the database and if it’s a specific name (i.e. John) it puts the background color to green else it puts it to white. You can even have a case statement and for each different names that you choose can be a different color in the table. You can also set the table row colors to go back and forth if you want. I can come up with code for you if you want to have alternating colors.

Hope this helps.

Name School Age

Thanks for the reply ,yes it helped me to a certain extent. :slight_smile:

I would like to customize it a bit more, if its possible.
What i want is , if i enter a new entry(a name) and select the appropriate highlight option, what would the code look like in the php side?

[code]Name:

Jr.High High School College Red Green Blue [/code]

The output page looks something like this:
[php]<?php
include “login.php”;
$output = mysql_query(“SELECT * FROM education”);
echo “”;
echo "

"; while($row = mysql_fetch_array($output)) { echo ""; echo ""; echo ""; echo "";

// assuming the highlighting code will come some where in here? //
echo “

”;
}

echo “

Serial No. Name School Age
" . $row['name'] . "" . $row['school'] . "" . $row['age'] . "
”;
echo “”;

?>[/php]

Hi again,

Are you talking about once you enter the information into the database and you display all of the information from the database you want to highlight the row that you just entered? Or use your form field as a search box and highlight all of the rows that have the name and the school type? I’m sorry but you need to be more specific in your request.

Thanks.

That’s exactly what i want.My apologies if i wasn’t clear enough.
I want to use my form field as a search box(search by the name i entered) and perform the highlight of that particular row. The highlight color can be chosen by the dropdown box.

Sponsor our Newsletter | Privacy Policy | Terms of Service