dty63504 2017-02-08 09:58
浏览 59

PHP如何使用rowspan单元格,并使用查询使其文本垂直

Attached you a shot, I want to merge cells in Kitchen Time column, and make time text to be vertical, I tried a lot but all I did just to hide cells if kitchen time was the same in below cells, and hide border, but it's not what I'm looking for! Here is the screenshot:

merge cells

Code:

<?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条回答 默认 最新

  • douluozhan4370 2017-02-08 11:55
    关注

    on go we cannot find the rowspan. for that

    1. find the count of rows to merge using query itself.
    2. loop the result and create a multi dimensional array and using array print the table
    3. create a string of html. keep a string for rowspan. replace that string with actual value at the end

    here is the sample with 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 ;
    

    Note: didn't executed the shared code. So check the logic and apply according to your result.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题