Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
嵌入在php脚本中的html代码_Php_Html - Fatal编程技术网

嵌入在php脚本中的html代码

嵌入在php脚本中的html代码,php,html,Php,Html,我想要一个带有php条件的td表中的按钮 这是我的php代码 <?php <table border="0"> <thead> <tr> <th>Order No</th> <th>Order Date </th> <th>Customer</th> <th>Total Price<

我想要一个带有php条件的td表中的按钮

这是我的php代码

  <?php

<table  border="0">
<thead>
      <tr>
        <th>Order No</th>
        <th>Order Date </th>
        <th>Customer</th>
        <th>Total Price</th>
        <th>Action</th>
      </tr>

    </thead>
    <tbody>
  ';
 foreach($query as $row)

 {
 $output .= '<tr class="heightSetting">
            <td>'.$row->purchase_order_no.'</td>
            <td>'.date("Y:m:d", strtotime($row->updatiion_date)).'</td>
            <td>'.$row->vendor_name.'</td>
            <td>'.$row->total_price.'</td>
            <td><input type="button" class="button modalLink btn" 
            view_id="'.$row->purchase_order_id.'" value="View"
            data-toggle="modal" data-target="#viewModal">
            <input type="button" class="deliver_status button btn" 
            id="'.$row->purchase_order_id.'" value="Delivered">
            </td>
         </tr>

         ';
 }
  $output .= '</table></tbody><br />';
echo $output;     

}
    }
 ?>

您可以使用缩写if/else语句

$output .= '<tr class="heightSetting">
        <td>'.$row->purchase_order_no.'</td>
        <td>'.date("Y:m:d", strtotime($row->updatiion_date)).'</td>
        <td>'.$row->vendor_name.'</td>
        <td>'.$row->total_price.'</td>
        <td><input type="button" class="button modalLink btn" 
        view_id="'.$row->purchase_order_id.'" value="View"
        data-toggle="modal" data-target="#viewModal">
        '.($row->delivery == 0?'<input type="button" class="deliver_status button btn" 
        id="'.$row->purchase_order_id.'" value="Delivered">':'').'
        </td>
     </tr>

     ';
$output.='
“.$row->采购订单号”
.date(“Y:m:d”,strotime($row->updateion_date))。'
“.$row->供应商名称”
“.$row->总价”
“。”($row->delivery==0?“”:“”)。”
';
摘录:

($row->delivery == 0?'<input type="button" class="deliver_status button btn" 
        id="'.$row->purchase_order_id.'" value="Delivered">':'')
($row->delivery==0?“”:“”)

在这里,我将原始代码更改如下。这里还添加了所有条件。我想这会对你有所帮助。将此代码段添加到.php代码的相关位置,并尝试一下

<?php if(!empty($query)): ?>
  <table  border="0">
    <thead>
      <tr>
        <th>Order No</th>
        <th>Order Date </th>
        <th>Customer</th>
        <th>Total Price</th>
        <th>Action</th>
      </tr>

    </thead>
    <tbody>
      <?php  foreach($query as $row): ?>
        <tr class="heightSetting">
          <td><?php echo $row->purchase_order_no; ?></td>
          <td><?php echo date("Y:m:d", strtotime($row->updatiion_date)); ?></td>
          <td><?php echo $row->vendor_name;?></td>
          <td><?php echo $row->total_price;?></td>
          <td>
            <?php if($row->delivery != 0):?>
                <input type="button" class="button modalLink btn" 
                      view_id="'<?php echo $row->purchase_order_id;?>'" value="View"
                      data-toggle="modal" data-target="#viewModal">
            <?else :?>
              <input type="button" class="deliver_status button btn" 
                 id="'<?php echo $row->purchase_order_id;?>'" value="Delivered">

            <?php endif;?>

          </td>

        </tr>

      <?php endforeach; ?>
    </tbody>
  </table>
<?php else: ?>               
    <div>
        <h3 class="errorShow">Data Not Found!</h3>
    </div>
<?php endif; ?>

订单号
订购日期
顾客
总价
行动
<?php if(!empty($query)): ?>
  <table  border="0">
    <thead>
      <tr>
        <th>Order No</th>
        <th>Order Date </th>
        <th>Customer</th>
        <th>Total Price</th>
        <th>Action</th>
      </tr>

    </thead>
    <tbody>
      <?php  foreach($query as $row): ?>
        <tr class="heightSetting">
          <td><?php echo $row->purchase_order_no; ?></td>
          <td><?php echo date("Y:m:d", strtotime($row->updatiion_date)); ?></td>
          <td><?php echo $row->vendor_name;?></td>
          <td><?php echo $row->total_price;?></td>
          <td>
            <?php if($row->delivery != 0):?>
                <input type="button" class="button modalLink btn" 
                      view_id="'<?php echo $row->purchase_order_id;?>'" value="View"
                      data-toggle="modal" data-target="#viewModal">
            <?else :?>
              <input type="button" class="deliver_status button btn" 
                 id="'<?php echo $row->purchase_order_id;?>'" value="Delivered">

            <?php endif;?>

          </td>

        </tr>

      <?php endforeach; ?>
    </tbody>
  </table>
<?php else: ?>               
    <div>
        <h3 class="errorShow">Data Not Found!</h3>
    </div>
<?php endif; ?>