Here is the code. I am trying to hi-lite rows that are generated that have a value of "Y" for column AA_letter_recd in yellow, the rows . The ones that have a value of "N" are not to be high-lited in yellow. Thanks.

<?php
/*Main Store Index */ 
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
$db_host = "xxx"; 
$db_username = "xxx";  
$db_pass = "xxx";   
$db_name = "xxx";   

mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database exists");  

// Run a select query to get my all (*) items from master list
//dynamic list is an empty string. depends on other factors

$examsdynamicList = "";

$sql = mysql_query("SELECT * FROM exams ORDER BY Exam_date");
$fileCount = mysql_num_rows($sql); // count the output amount
if ($filecount > 0) {

/*get all the matter details*/

while($row = mysql_fetch_array($sql)){

$id = $row["id"];
$File_no = $row["File_no"];
$EE_name = $row["EE_name"];
$Doctor = $row["Doctor"];
$Exam_date = $row["Exam_date"];
$Appointment_letter_date = $row["Appointment_letter_date"];
$Joint_letter_sent_date = $row["Joint_letter_sent_date"];
$Sent_to_doctor_date = $row["Sent_to_doctor_date"];
$Type = $row["Type"];
$Notes1 = $row["Notes1"];
$Notes2 = $row["Notes2"];
$Notes3 = $row["Notes3"];
$AA_letter_recd = $row["AA_letter_recd"];

if ($AA_letter_recd == "Y")

$examsdynamicList .= '

<tr style="background-color: Yellow;">
    <td>' . $EE_name . '</td>
    <td>' . $File_no . '</td>
    <td>' . $Doctor . '</td>
    <td>' . $Exam_date . '</td>
    <td>' . $Appointment_letter_date . '</td>
    <td>' . $Joint_letter_sent_date . '</td>
    <td>' . $Sent_to_doctor_date . '</td>
    <td>' . $Type . '</td>
    <td>' . $Notes1 . '</td>
    <td>' . $Notes2 . '</td>
    <td>' . $Notes3 . '</td>
    <td>' . $AA_letter_recd . '</td>
    </tr>

';


if ($AA_letter_recd == "N")

$examsdynamicList .= '

<tr>
    <td>' . $EE_name . '</td>
    <td>' . $File_no . '</td>
    <td>' . $Doctor . '</td>
    <td>' . $Exam_date . '</td>
    <td>' . $Appointment_letter_date . '</td>
    <td>' . $Joint_letter_sent_date . '</td>
    <td>' . $Sent_to_doctor_date . '</td>
    <td>' . $Type . '</td>
    <td>' . $Notes1 . '</td>
    <td>' . $Notes2 . '</td>
    <td>' . $Notes3 . '</td>
    <td>' . $AA_letter_recd . '</td>
    </tr>

';


}


} else {
    $examsdynamicList = "Sorry! Master List is Unavailable. Please try again later.";
}
mysql_close();
?>
if(condition)
{
//do stuff
}
Member Avatar for diafol

No need for 41-82.

$class = ($AA_letter_recd == "Y") ? ' class="highlight"' : '';
$examsdynamicList .= '
<tr'.$class.'>
    <td>' . $EE_name . '</td>
    <td>' . $File_no . '</td>
    <td>' . $Doctor . '</td>
    <td>' . $Exam_date . '</td>
    <td>' . $Appointment_letter_date . '</td>
    <td>' . $Joint_letter_sent_date . '</td>
    <td>' . $Sent_to_doctor_date . '</td>
    <td>' . $Type . '</td>
    <td>' . $Notes1 . '</td>
    <td>' . $Notes2 . '</td>
    <td>' . $Notes3 . '</td>
    <td>' . $AA_letter_recd . '</td>
    </tr>
';

Then in your css:

.highlight
{
    background-color: yellow; //use the hex value though
}

Thank you. But the CSS you instruct..Doesn't that just make all rows yellow? I want rows with a value "Y" pulled from MySQL database to be high-lited yellow on the output .php webpage. In turn, I want the rows pulled with value "N" (This is for $AA_letter_recd) to not be high-lited.

Member Avatar for diafol

Have you tried it?

Sorry, I glossed over the part where you added the $class stuff. Yes, I tried.

I did add the class to css too. Here is the code i have now:

<?php
/*Main Store Index */ 
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
$db_host = "xxx"; 
$db_username = "xxx";  
$db_pass = "xxx";   
$db_name = "xxx";   

mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database exists");  

// Run a select query to get my all (*) items from master list
//dynamic list is an empty string. depends on other factors

$examsdynamicList = "";

$sql = mysql_query("SELECT * FROM exams ORDER BY EE_name");
$fileCount = mysql_num_rows($sql); // count the output amount
if ($fileCount > 0) {

/*get all the matter details*/

while($row = mysql_fetch_array($sql)){

$id = $row["id"];
$Doctor = $row["Doctor"];
$File_no = $row["File_no"];
$EE_name = $row["EE_name"];
$Exam_date = $row["Exam_date"];
$Appointment_letter_date = $row["Appointment_letter_date"];
$Joint_letter_sent_date = $row["Joint_letter_sent_date"];
$Sent_to_doctor_date = $row["Sent_to_doctor_date"];
$Type = $row["Type"];
$Notes1 = $row["Notes1"];
$Notes2 = $row["Notes2"];
$Notes3 = $row["Notes3"];
$AA_letter_recd = $row["AA_letter_recd"];
$class = ($AA_letter_recd == "Y") ? ' class="highlight"' : '';
$examsdynamicList .= '
<tr'.$class.'>
    <td>' . $EE_name . '</td>
    <td>' . $File_no . '</td>
    <td>' . $Doctor . '</td>
    <td>' . $Exam_date . '</td>
    <td>' . $Appointment_letter_date . '</td>
    <td>' . $Joint_letter_sent_date . '</td>
    <td>' . $Sent_to_doctor_date . '</td>
    <td>' . $Type . '</td>
    <td>' . $Notes1 . '</td>
    <td>' . $Notes2 . '</td>
    <td>' . $Notes3 . '</td>
    <td>' . $AA_letter_recd . '</td>
    </tr>
'';}

} else {
    $examsdynamicList = "Sorry! Master List is Unavailable. Please try again later.";
}
mysql_close();
?>

the list is being populated, but the color assigned in CSS is not being applied to the rows with value Y. I had an earlier syntax error here, but I fixed it. It was an extra "'"

Thank you.

Solved, I had a script running defining table styles in another php file. Thank you!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.