i am running ubuntu 22.04 and php 8.1 / MariaDB , i am missing somthing here in my code just can't see it. the premise of the code is to look at the TrolleyID Field and if it's '00000' basically echo's "BAD-READ" else it's 'GOOD-READ' any help would be great . thank you

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<?php

$hostname = "localhost";
$username = "xxx";
$password = "xxx";
$db = "xxxxx";
$dbconnect=mysqli_connect($hostname,$username,$password,$db);

if ($dbconnect->connect_error) {
  die("Database connection failed: " . $dbconnect->connect_error);
}

?>

<table width="511" border="1" align="center">
<tr>
  <td width="133">Date</td>
  <td width="148">Time</td>
  <td width="208">TrolleyID</td>
  <td width="208">Status</td>
</tr>


        <?php
        while($res = mysqli_fetch_array($result)) {     

            $stat=$res['trolleyID'];
            if($stat=="000000")
            {
                $color="color:red";
                $text="BAD READ";
            }
            else 
            {
                $color="color:green";
                $text="GOOD READ";
            }

            echo "<tr>";
                echo "<td>".$res['datecol']."</td>";
                echo "<td>".$res['timecol']."</td>";
                echo "<td>".$res['trolleyID']."</td>";
                echo "<td style='$color'>".$text."</td>"; 
            echo "</tr>";

        }
        ?>

</table>
</body>
</html>

Hi all, i Fixed it . just so someone else has this issue, here is what i did

<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "xxx", "xxx", "xxxxx");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Attempt select query execution
$sql = "SELECT * FROM datalog";
if($result = mysqli_query($link, $sql)){
    if(mysqli_num_rows($result) > 0){
        echo "<table>";
            echo "<tr>";
                echo "<th>id</th>";
                echo "<th>datecol</th>";
                echo "<th>timecol</th>";
                echo "<th>TrolleyID</th>";
                echo "<th>status</th>";
            echo "</tr>";
        while($row = mysqli_fetch_array($result)){


          $stat=$row['trolleyID'];
            if($stat=="000000")
            {
                $color="color:red";
                $text="BAD READ";
            }
            else 
            {
                $color="color:green";
                $text="GOOD READ";
            }




            echo "<tr>";
                echo "<td>" . $row['id'] . "</td>";
                echo "<td>" . $row['datecol'] . "</td>";
                echo "<td>" . $row['timecol'] . "</td>";
                echo "<td>" . $row['trolleyID'] . "</td>";
                echo "<td style='$color'>".$text."</td>";


            echo "</tr>";
        }
        echo "</table>";
        // Free result set
        mysqli_free_result($result);
    } else{
        echo "No records matching your query were found.";
    }
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?><?php

Glad to hear you got your question answered by yourself. It's a rewarding feeling, right?

Thank you for updating the forum thread with what you did so it can help others.

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.