Bootstrap 我正在尝试根据值更改一列

cuxqih21  于 2023-03-06  发布在  Bootstrap
关注(0)|答案(2)|浏览(129)
<?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();

?>

如果乘积变小,则颜色将变为红色,但它将执行整个列,如果这有意义,我只想执行列中的一行。
我只是尝试更改$row[count],尝试根据计数更改单列。如果计数小于10,则它将变为红色。如果不是什么都没有发生?

jbose2ul

jbose2ul1#

如果你的表显示多行请分享查询和foreach的源代码,无论如何我看到很多问题在你的代码:

  1. <image>标记在html中不存在,并且不需要结束标记,正确格式为:<img src="" />
    1.您可以在一行中创建警报表td:
<td data-column="count" 
    class="<?=($row['count'] > 10 ? 'alert-danger' : 'alert-success');?>" 
    id="count"> 
      <?php echo $row['count']; ?>
 </td>

1.如果要为整行着色:

<tr id="<?php echo $row['id']; ?>" 
    class="<?=($row['count'] > 10 ? 'alert-danger' : 'alert-success');?>" >
rkue9o1l

rkue9o1l2#

<?php
include './PHP/serverconn.php';
include './PHP/login.php';
include 'InventoryPages\testingautoupdate.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 'InventoryPages\updatemodel.php';
} ?>
  <?php } else { 
    echo 'No results found';
  }
  

$conn->close();

?>

这一切都是固定的,这是我没有注意的东西标志,我正在使用。

相关问题