skip to Main Content
<?php
include './PHP/serverconn.php';
include './PHP/login.php';
$itemid = '';
$sql = "SELECT id, ItemName, ItemBarcode, CompanyName, OurBarcode, DetailsOnItem, barcodeimg, count, combindedBarcode, modelnumber FROM items";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    $itemid = $row['id'];    
  ?>
    <tbody>
    <tr id="<?php echo $row['id']; ?>" >
      <th> <?php echo $row['id']; ?></th>
      <td data-column='ItemName' id="ItemName"><?php echo $row['ItemName']; ?></td>
      <td data-column='ItemBarcode' id="ItemBarcode"><?php echo $row['ItemBarcode']; ?></td>
      <td data-column='CompanyName' id="CompanyName"><?php echo  $row['CompanyName']; ?></td>
      <td data-column='OurBarcode' id="OurBarcode"><?php echo $row['OurBarcode']; ?></td>
      <td data-column='DetailsOnItem' id="DetailsOnItem"><?php echo $row['DetailsOnItem']; ?></td>
      <td data-column='DetailsOnItem' id="DetailsOnItem"><?php echo $row['modelnumber']; ?></td>
      <td data-column='barcodeimg' id="barcodeimg" class='warning'><image src='<?php echo $row['barcodeimg']; ?>'></img></td>
      <td data-column="count" 
    class="<?=($row['count'] > 10 ? 'alert-danger' : 'alert-success');?>" 
    id="count"> 
      <?php echo $row['count']; ?>
 </td> 
      <td data-column='combindedBarcode' id="combindedBarcode"><?php echo $row['combindedBarcode']; ?></td>
    <td>
    <?php if($_SESSION['admin'] > 0){?>

<div class='btn-group'>
    <button type='sumbit' name='edit' class='btn btn-sm btn-secondary' data-toggle="modal" data-target="#modal-large" >
        <i class='fa fa-pencil'></i>
    </button>
    <a type='sumbit' name='delete' id='delete' href='/delete.php?id=<?php echo $itemid; ?>&logged_id=<?php echo $_SESSION['admin']; ?>' class='btn btn-sm btn-secondary' data-toggle='tooltip' title='Delete'>
        <i class='fa fa-times'></i>
    </a>
</div>
<?php ;} else { ?>
  <div class='btn-group' disabled>
    <button type='sumbit' name='edit' class='btn btn-sm btn-secondary'  data-toggle="modal" data-target="#modal-large">
        <i class='fa fa-pencil'></i>
    </button>
    <a type='sumbit' name='delete' id='delete' href='/delete.php?id=<?php echo $itemid; ?>&authed=<?php echo $_SESSION['admin']; ?>' class='btn btn-sm btn-secondary' data-toggle='tooltip' title='Delete' disabled>
        <i class='fa fa-times'></i>
    </a>
  <?php ;} ?>
    </td>  
    </tr> 
      <?php } ?>
    </tbody>
  
  <?php } else { 
    echo 'No results found';
  }
  


$conn->close();

?>

if that product is getting low then will change color to red but its doing the whole column if that makes sense I just wanna do one row out of the column.

I am only trying to change the $row[count] trying to change single column based on the count. If count is under 10 then it will change to red. if not nothing happens?

2

Answers


  1. Chosen as BEST ANSWER
    <?php
    include './PHP/serverconn.php';
    include './PHP/login.php';
    include 'InventoryPagestestingautoupdate.php';
    $itemid = '';
    $sql = "SELECT id, ItemName, ItemBarcode, CompanyName, `Location`, DetailsOnItem, barcodeimg, count, combindedBarcode, modelnumber FROM items";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
      // output data of each row
      while($row = $result->fetch_assoc()) {
        $itemid = $row['id'];    
        $count =$row['count'];
          ?>
        <tr id="<?php echo $row['id']; ?>" >
          <th scope="row"> <?php echo $row['id']; ?></th>
          <td data-column='ItemName' id="ItemName"><?php echo $row['ItemName']; ?></td>
          <td data-column='ItemBarcode' id="ItemBarcode"><?php echo $row['ItemBarcode']; ?></td>
          <td data-column='CompanyName' id="CompanyName"><?php echo  $row['CompanyName']; ?></td>
          <td data-column='Location' id="Location"><?php echo $row['Location']; ?></td>
          <td data-column='DetailsOnItem' id="DetailsOnItem"><?php echo $row['DetailsOnItem']; ?></td>
          <td data-column='DetailsOnItem' id="DetailsOnItem"><?php echo $row['modelnumber']; ?></td>
          <td data-column='barcodeimg' id="barcodeimg" class='warning'><img src='<?php echo $row['barcodeimg']; ?>'/></td>
          <?php if($count < 10) {echo "<td data-column='count' class='alert-warning' id='count'> $count </td> ";}else{echo "<td data-column='count' class='alert-success' id='count'> $count </td> ";}?>
          <td data-column='combindedBarcode' id="combindedBarcode"><?php echo $row['combindedBarcode']; ?></td>
        <td>
        <?php if($_SESSION['admin'] > 0){?>
    
    <div class='btn-group'>
        <button type='sumbit' name='edit' class='btn btn-sm btn-secondary' data-toggle="modal" data-target="#modal<?php echo $itemid;?>" >
            <i class='fa fa-pencil'></i>
        </button>
        <a type='sumbit' name='delete' id='delete' href='/delete.php?id=<?php echo $itemid; ?>&logged_id=<?php echo $_SESSION['admin']; ?>' class='btn btn-sm btn-secondary' data-toggle='tooltip' title='Delete'>
            <i class='fa fa-times'></i>
        </a>
    </div>
    <?php ;} else { ?>
      <div class='btn-group' disabled>
        <button type='sumbit' name='edit' class='btn btn-sm btn-secondary'  data-toggle="modal" data-target="#modal<?php echo $itemid;?>">
            <i class='fa fa-pencil'></i>
        </button>
        <a type='sumbit' name='delete' id='delete' href='/delete.php?id=<?php echo $itemid; ?>&authed=<?php echo $_SESSION['admin']; ?>' class='btn btn-sm btn-secondary' data-toggle='tooltip' title='Delete' disabled>
            <i class='fa fa-times'></i>
        </a>
      <?php ;} ?>
        </td>  
        </tr> 
        <?php include 'InventoryPagesupdatemodel.php';
    } ?>
      <?php } else { 
        echo 'No results found';
      }
      
    
    $conn->close();
    
    ?>
    

    Its all fixed it was me not paying attention to thing signs I was using.


  2. if your table displays multiple rows please share the query and the source code of the foreach, anyway i see lot of problem in your code:

    1. <image> tag does not exist in html and it does not need a closing tag, the correct format: <img src="" />

    2. you make the alert table td in one line:

    <td data-column="count" 
        class="<?=($row['count'] > 10 ? 'alert-danger' : 'alert-success');?>" 
        id="count"> 
          <?php echo $row['count']; ?>
     </td> 
    
    1. if you want to color the whole row :
    <tr id="<?php echo $row['id']; ?>" 
        class="<?=($row['count'] > 10 ? 'alert-danger' : 'alert-success');?>" >
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search