我想知道如何在PHP代码中使用表格内的div标签。这是我的代码。请告诉我如何正确使用它。
<tbody>
<?php
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result,MYSQLI_BOTH)) {
echo "<tr>
<td>{$row['id']}</td>
<td><img width='90px' height='90px' src='imageView.php?id=".$row["id"]."' /> </td>
<td>{$row['item_name']}</td>
<td>{$row['description']}</td>
<td>{$row['quantity']}</td>
<td>echo '<div class="col-md-1 col-sm-3 col-xs-6 c-cart-qty">
<div class="c-input-group c-spinner">
<input type="text" class="form-control c-item-1" value="1">
<div class="c-input-group-btn-vertical">
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-up"></i>
</button>
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-down"></i>
</button>
</div>
</div>
</div>
</td>';
<td> <button>submit</button> </td>
</tr>";
}?>
</tbody>
我尝试使用倒置的逗号和大括号但仍显示错误。需要做什么?
答案 0 :(得分:4)
您可以在内部表中编写div
。不要将所有表放在php标签内。删除<?php ?>
php代码之外的html。之后,只要你想echo
任何值,只需使用php。
自定义您的代码,如下所示
<table>
<tbody>
<?php
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><img width='90px' height='90px' src='imageView.php?id=<?php echo $row["id"]; ?>' /> </td>
<td><?php echo $row['item_name']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td>
<div class="col-md-1 col-sm-3 col-xs-6 c-cart-qty">
<div class="c-input-group c-spinner">
<input type="text" class="form-control c-item-1" value="1">
<div class="c-input-group-btn-vertical">
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-up"></i>
</button>
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-down"></i>
</button>
</div>
</div>
</div>
</td>
<td> <button>submit</button> </td>
</tr>
<?php } ?>
</tbody>
</table>
答案 1 :(得分:0)
在双引号中,您可以使用单引号
<tbody>
<?php
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result,MYSQLI_BOTH)) {
echo "<tr>
<td>{$row['id']}</td>
<td><img width='90px' height='90px' src='imageView.php?id=".$row["id"]."' /> </td>
<td>{$row['item_name']}</td>
<td>{$row['description']}</td>
<td>{$row['quantity']}</td>
<td><div class='col-md-1 col-sm-3 col-xs-6 c-cart-qty'>
<div class='c-input-group c-spinner'>
<input type='text' class='form-control c-item-1' value='1'>
<div class='c-input-group-btn-vertical'>
<button class='btn btn-default' type='button' data_input='c-item-1'>
<i class='fa fa-caret-up'></i>
</button>
<button class='btn btn-default' type='button' data_input='c-item-1'>
<i class='fa fa-caret-down'></i>
</button>
</div>
</div>
</div>
</td>;
<td> <button>submit</button> </td>
</tr>";
}?>
</tbody>