bob don bob don - 7 months ago 24
HTML Question

Highlight only first row of data

I am trying to include a row being highlighted in my table. My data that goes into the table is set up as follows. I have an html page where data is inputted. From that page, I have a separate php file which will write those results to a text file. I then have another php file which reads the data from the text file and places the data into a table. That data is then sorted because the data being inputted will be inputted at different times. Since the data is being sorted dynamically, my question is, how do i highlight the first row of that table? The first row in my case, will have the fastest time.

This is my html page.

<html>

<form method = "POST" action = "TimeSubmitFinal.php" target = "TimeSubmitFinal.php">

<table>
<tr>
<td><h3> Group 1 </h3></td>
</tr>
<tr>
<td> Site: <b><label value = "ASH" readonly = "true" size = "4" name = "ASH" id = "ash"> ASH</label></td>
<td> Run Time: <input type = "text" size = "5" id = "ash_run" class = "run" name = "ash_run" value = "TBD"> </td>
<td> Penalty: <input type = "text" class = "penalty" size = "5" id = "ash_pen" name = "ash_pen" value = "TBD"> </td>
<td> Completed Time: <input type = "text" readonly = "true" size = "5" id = "ash_com" name = "ash_com" class = "com" value = "TBD"> </td>
<td> <input type = "button" value = "calculate" onclick = ashcalc() id = "ashcalcu"> </td>
</tr>

<tr>
<td> Site: <b><label value = "ATL" readonly = "true" size = "4" name = "ATL" id = "atl"> ATL </label></td>
<td> Run Time: <input type = "text" size = "5" id = "atl_run" class = "run" name = "atl_run" value = "TBD"> </td>
<td> Penalty: <input type = "text" class = "penalty" size = "5" id = "atl_pen" name = "atl_pen" value = "TBD"> </td>
<td> Completed Time: <input type = "text" readonly = "true" size = "5" id = "atl_com" name = "atl_com" class = "com" value = "TBD"> </td>
<td> <input type = "button" value = "calculate" onclick = atlcalc()> </td>
</tr>
<tr>
<td> Site: <b><label value = "COL" readonly = "true" size = "4" name = "COL" id = "col"> COL</label></td>
<td> Run Time: <input type = "text" size = "5" id = "col_run" class = "run" name = "col_run" value = "TBD"> </td>
<td> Penalty: <input type = "text" class = "penalty" size = "5" id = "col_pen" name = "col_pen" value = "TBD"> </td>
<td> Completed Time: <input type = "text" readonly = "true" size = "5" id = "col_com" name = "col_com" class = "com" value = "TBD"> </td>
<td> <input type = "button" value = "calculate" onclick = colcalc() id = "colcalcu"> </td>
</tr>
<tr>
<td> Site: <b><label value = "SAV" readonly = "true" size = "4" name = "SAV" id = "sav"> SAV</label></td>
<td> Run Time: <input type = "text" size = "5" id = "sav_run" class = "run" name = "sav_run" value = "TBD"> </td>
<td> Penalty: <input type = "text" class = "penalty" size = "5" id = "sav_pen" name = "sav_pen" value = "TBD"> </td>
<td> Completed Time: <input type = "text" readonly = "true" size = "5" id = "sav_com" name = "sav_com" class = "com" value = "TBD"> </td>
<td> <input type = "button" value = "calculate" onclick = savcalc() id = "savcalcu"> </td>
</tr>
<tr>
<td><input type = "submit" value = "Submit"> </input></td>
</tr>
</table>

</form>
</html


This is my first php page

<?php
//make sure text file is in directory
$txt1 = file("data1.txt");

//Group1 POSTS
$ash = 'ASH';
$ashrun = $_POST['ash_run'];
$ashpen = $_POST['ash_pen'];
$ashcom = $_POST['ash_com'];

$atl = 'ATL';
$atlrun = $_POST['atl_run'];
$atlpen = $_POST['atl_pen'];
$atlcom = $_POST['atl_com'];

$col = 'COL';
$colrun = $_POST['col_run'];
$colpen = $_POST['col_pen'];
$colcom = $_POST['col_com'];

$sav = 'SAV';
$savrun = $_POST['sav_run'];
$savpen = $_POST['sav_pen'];
$savcom = $_POST['sav_com'];

$result1 = '';


foreach($txt1 as $line1)
{
if(substr($line1,0,3) == 'ASH')
{
$result1 .= $ash. ' '. $ashrun. ' '. $ashpen. ' '. $ashcom. "\r\n".
$atl. ' '. $atlrun. ' '. $atlpen. ' '. $atlcom. "\r\n".
$col. ' '. $colrun. ' '. $colpen. ' '. $colcom. "\r\n".
$sav. ' '. $savrun. ' '. $savpen. ' '. $savcom. "\r\n";
}
}

file_put_contents("data1.txt", $result1);

?>


This is my php that displays the data

<html>
<head>

<?php

$lines = file("data.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$data = array_map(function($v){
list($site, $runtime, $pentime, $comtime) = explode(" ", $v);
return ["site" => $site, "runtime" => $runtime, "pentime" => $pentime, "comtime" => $comtime];
}, $lines);

usort($data, function($a, $b){
if($a["comtime"] == $b["comtime"])
return 0;
return $a["comtime"] > $b["comtime"] ? 1 : -1;
});

</head>

<body onload = "timedRefresh(10000)">

<table class = "centertab">
<tr>
<td>
<table border = "1" id = "table3" class = "tablesorter" style = "font-size: 20pt">

<thead>
<caption style = "font-size: 25pt; font-weight:bold;"> Eastern Region </caption>
<tr>

<th> Site </th>
<th> Run Time </th>
<th> Penalty Time </th>
<th class = "string-max"> Complete Time </th>
</tr>
</thead>
<tbody>

<?php foreach($data1 as $site1) { ?>
<tr>

<td> <b><?php echo $site1["site"]; ?> </td>
<td> <b><?php echo $site1["runtime"];?> </td>
<td> <b><?php echo $site1["pentime"]; ?> </td>
<td> <b><?php echo $site1["comtime"]; ?> </td>
</tr>
<?php } ?>
</tbody>
</table>
</td>
</tr>
</table>

</body>
</html>

Answer

Add the following code to your CSS file:

.tablesorter tbody tr:first-child td {
    background-color: #FFFF66;
}

Change the color code to the color you prefer.