Home > Blockchain >  jquery or php if X is greater than Y
jquery or php if X is greater than Y

Time:04-05

I'm making a website that displays a basic crud that shows Companyname, Stock, Minumum, Maximum.

I would like to display an alert or a message somewhere if the Stock is greater than the maximum. How could I go about doing this? Here is my display page code.

<table >
    <thead>
        <tr>
        <th>ID</th>
        <th>Company Name</th>
        <th>Stock</th>
        <th>Minumum</th>
        <th>Maximum</th>
        <th>Action</th>
    </tr>
    </thead>

    <tbody> 
        <?php
            if ($result->num_rows > 0) {
                while ($row = $result->fetch_assoc()) {
        ?>
                    <tr>
                    <td><?php echo $row['id']; ?></td>
                    <td><?php echo $row['companyname']; ?></td>
                    <td><?php echo $row['stock']; ?></td>
                    <td><?php echo $row['minumum']; ?></td>         
                    <td><?php echo $row['maximum']; ?></td>
                    <td><a  href="update1.php?id=<?php echo $row['id']; ?>">Edit</a>&nbsp;<a  href="delete1.php?id=<?php echo $row['id']; ?>">Delete</a></td>
                    </tr>   

CodePudding user response:

You can put an additional message in the Stock column with an if statement.

<td><?php echo $row['stock']; ?></td>

with

<td><?php echo $row['stock']; if ($row['stock'] > $row['maximum']) { echo " > maximum"; } ?></td>
  • Related