gpt4 book ai didi

PHP 如何跨行单元格,并使用查询使它们的文本垂直

转载 作者:行者123 更新时间:2023-11-28 04:22:57 24 4
gpt4 key购买 nike

给你拍了张照片,我想合并厨房时间列中的单元格,并使时间文本垂直,我尝试了很多但我所做的只是隐藏单元格,如果厨房时间在下面的单元格中相同,并隐藏边框,但这不是我要找的!这是屏幕截图:

merge cells

代码:

<?php
include_once("config.php");
if ($conn -> connect_error > 0) {
die('Unable to connect to database [' . $conn -> connect_error . ']');}?>

<table id = "table" class = "table table-bordered">
<thead class = "alert-info">
<tr>
<th>Kitchen Time</th>
<th>Order#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Address</th>
<th>Driver#</th>
<th>Delivery Time</th>
<th># of People</th>
<th>Miles</th> </tr>
</thead><tbody>
<?php
$dtpickerdate = isset($_POST['dtpickerdate']) ? $_POST['dtpickerdate'] : NULL;
$q_customer = $conn->query
("SELECT * from orders inner JOIN customer_order on customer_order.order_no =orders.order_no AND customer_order.order_date like'$dtpickerdate' AND
orders.date like'$dtpickerdate' inner join driver_order on driver_order.order_no=orders.order_no and driver_order.order_date like'$dtpickerdate'
LEFT JOIN customer on customer.phone=customer_order.phone order by k_time,time desc" ) or die(mysqli_error());

$k_time = '';


while($f_customer = $q_customer->fetch_array()){?>
<tr>
<?php
{
if($k_time == '' || $k_time != $f_customer['k_time']){
$k_time = $f_customer['k_time'];

echo '<td align="center" > <span style="font-weight:bold;">' .$f_customer['k_time']. '</td>';

} else{
echo "<td style='border: none;'>&nbsp;</td>";
}?>
<td align='center' span style="font-weight:bold;"><a data-controls-modal="action" data-backdrop="static" data-keyboard="false" href="options.php?id=<?php echo $f_customer['order_no']?>&date=<?php echo $dtpickerdate?>" data-toggle = "modal" data-target = "#action"><?php echo $f_customer['order_no']?></a></td>

<?php
echo "<td>" .$f_customer['first_name']."</td>";
echo "<td>". $f_customer['last_name']."</td>";
echo "<td>". $f_customer['address']."</td>";
echo "<td>". $f_customer['driver_no']."</td>";
echo "<td>". $f_customer['d_time']."</td>";
echo "<td>". $f_customer['no_ofppl']."</td>";
echo "<td>". $f_customer['km']."</td>";

} }

?>
</tbody>
</table>

最佳答案

继续我们找不到行跨度。为此

  1. 使用查询本身找到要合并的行数。
  2. 循环结果并创建一个多维数组并使用数组打印表格
  3. 创建一个 html 字符串。为 rowspan 保留一个字符串。在末尾用实际值替换该字符串

这是 3 的示例

<?php
include_once("config.php");
if ($conn -> connect_error > 0) {
die('Unable to connect to database [' . $conn -> connect_error . ']');
}
$tbody = '<table id = "table" class = "table table-bordered">
<thead class = "alert-info">
<tr>
<th>Kitchen Time</th>
<th>Order#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Address</th>
<th>Driver#</th>
<th>Delivery Time</th>
<th># of People</th>
<th>Miles</th> </tr>
</thead>
<tbody>';
$dtpickerdate = isset($_POST['dtpickerdate']) ? $_POST['dtpickerdate'] : NULL;
$q_customer = $conn->query
("SELECT * from orders inner JOIN customer_order on customer_order.order_no =orders.order_no AND customer_order.order_date like'$dtpickerdate' AND
orders.date like'$dtpickerdate' inner join driver_order on driver_order.order_no=orders.order_no and driver_order.order_date like'$dtpickerdate'
LEFT JOIN customer on customer.phone=customer_order.phone order by k_time,time desc" ) or die(mysqli_error());

$k_time = '';
$kTimeArry = array();

while($f_customer = $q_customer->fetch_array()){
$tbody .= "<tr>";
if ($k_time == '' || $k_time != $f_customer['k_time']) {//assign a hardcoded string for indicating rowspan. will replace acxtual value at the end
$k_time = $f_customer['k_time'];
$tbody .= '<td align="center" rowspan="###rowspan_'.$f_customer['k_time'].'"> <span style="font-weight:bold;">' .$f_customer['k_time']. '</td>';
}
$kTimeArry[$f_customer['k_time']] = $kTimeArry[$f_customer['k_time']]+1;//array to find rowspan
$tbody .= "<td align='center' span style=\"font-weight:bold;\">".
"<a data-controls-modal=\"action\" data-backdrop=\"static\" data-keyboard=\"false\"".
"href=\"options.php?id={$f_customer['order_no']}&date=$dtpickerdate\" ".
"data-toggle = \"modal\" data-target = \"#action\">{$f_customer['order_no']}</a></td>";

$tbody .= "<td>" .$f_customer['first_name']."</td>";
$tbody .= "<td>". $f_customer['last_name']."</td>";
$tbody .= "<td>". $f_customer['address']."</td>";
$tbody .= "<td>". $f_customer['driver_no']."</td>";
$tbody .= "<td>". $f_customer['d_time']."</td>";
$tbody .= "<td>". $f_customer['no_ofppl']."</td>";
$tbody .= "<td>". $f_customer['km']."</td>";
$tbody .= "</tr>";
}
$tbody .= "</tbody>
</table>";
foreach ($kTimeArry AS $ktime => $ktimeCount) {//'###rowspan_'.$ktime replace string with corresponding rowspan
$tbody = str_replace('###rowspan_'.$ktime, $ktimeCount, $tbody);
}
//print table
echo $tbody ;

注意:没有执行共享代码。因此,请检查逻辑并根据您的结果应用。

关于PHP 如何跨行单元格,并使用查询使它们的文本垂直,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42109900/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com