簡體   English   中英

表標題有時在沒有數據的情況下排列

[英]Table headings not lining it sometimes when there is data in them

我有一個為裝瓶時間表創建的日歷。 您可以將項目從一種數據拖放到另一種,它會更新數據庫。 這部分工作正常。

http://thereal805productions.com/calendar/calendar.php

但是,由於某些原因,標題“有時”在其中包含數據時無法正確排列。 它們將落在應位於其下方0.5至1個表格單元之間的某個位置。 我敢肯定這只是腦筋急轉彎,但我無法弄清楚。

任何幫助表示贊賞。

我認為違反了代碼的部分在這里:

while ( $day_num <= $days_in_month )  {
    $matched = false;
     ?>
            <td>  <!-- this should be a table inside each date  -->
            <table>
                <th> <div id = "<?php echo $myDate ?>" class = "droppable ui-widget-header" > <?php echo $day_num ?> </div> </th>

                <?php 
                $result = $conn->query($sql);
                foreach ($result as $row) {
                    // echo "row = " . $row['date'] . " and myDate = " . $myDate;
                    if ($row['botdate'] == $myDate) { ?>
                        <tr><td><div id = '<?php echo $row['id'] ?>' class="draggable ui-widget-content "> <?php echo $row['productId']; ?> </div></td></tr>


                    <?php $matched = true; }  else if ($matched == false) { ?>
                        <tr><td> </td></tr>
                <?php   }

                } ?>  <!-- ends the foreach  -->
            </table>
        </td>  <!-- ends the table inside each date  -->


    <?php


     $day_num++;

     $day_count++;
    $myDate = strtotime("+1 day", strtotime($myDate));
    $myDate = date("Y-m-d", $myDate);

     //Make sure we start a new row every week

     if ($day_count > 7)  {
         echo "</tr><tr>";
         $day_count = 1;
         }

}  // ends the while loop

可能不需要完整的代碼,但出於完整性考慮,我將其包括在內。

<?php
require_once('../includes/connection.inc.php');
 //This gets today's date

 $date =time () ;

 //This puts the day, month, and year in seperate variables

 $day = date('d', $date) ;

 $month = date('m', $date) ;

 $year = date('Y', $date) ;



 //Here we generate the first day of the month

 $first_day = mktime(0,0,0,$month, 1, $year) ;



 //This gets us the month name

 $title = date('F', $first_day) ;

 //Here we find out what day of the week the first day of the month falls on
 $day_of_week = date('D', $first_day) ;



 //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero

 switch($day_of_week){

 case "Sun": $blank = 0; break;

 case "Mon": $blank = 1; break;

 case "Tue": $blank = 2; break;

 case "Wed": $blank = 3; break;

 case "Thu": $blank = 4; break;

 case "Fri": $blank = 5; break;

 case "Sat": $blank = 6; break;

 }



 //We then determine how many days are in the current month

 $days_in_month = cal_days_in_month(0, $month, $year) ;


 //Here we start building the table heads
?>
 <table border=1 id = 'calendar'>

 <tr>

    <th colspan=7> <?php echo $title." ". $year; ?></th>


 </tr>

     <tr>
        <th class = 'weekday' width=42>S</th>
        <th class = 'weekday' width=42>M</th>
        <th class = 'weekday' width=42>T</th>
        <th class = 'weekday' width=42>W</th>
        <th class = 'weekday' width=42>T</th>
        <th class = 'weekday' width=42>F</th>
        <th class = 'weekday' width=42>S</th>
     </tr>




<?php
 //This counts the days in the week, up to 7

 $day_count = 1;



 echo "<tr>";

 //first we take care of those blank days

 while ( $blank > 0 )    {

     echo "<td></td>";

     $blank = $blank-1;

     $day_count++;

     }

 //sets the first day of the month to 1

 $day_num = 1;
 $myDate = '2014-05-01';
 $conn = dbConnect();
 $sql = ('SELECT * FROM bottling');





 //count up the days, untill we've done all of them in the month

while ( $day_num <= $days_in_month )  {
    $matched = false;
     ?>
            <td>  <!-- this should be a table inside each date  -->
            <table>
                <th> <div id = "<?php echo $myDate ?>" class = "droppable ui-widget-header" > <?php echo $day_num ?> </div> </th>

                <?php 
                $result = $conn->query($sql);
                foreach ($result as $row) {
                    // echo "row = " . $row['date'] . " and myDate = " . $myDate;
                    if ($row['botdate'] == $myDate) { ?>
                        <tr><td><div id = '<?php echo $row['id'] ?>' class="draggable ui-widget-content "> <?php echo $row['productId']; ?> </div></td></tr>


                    <?php $matched = true; }  else if ($matched == false) { ?>
                        <tr><td> </td></tr>
                <?php   }

                } ?>  <!-- ends the foreach  -->
            </table>
        </td>  <!-- ends the table inside each date  -->


    <?php


     $day_num++;

     $day_count++;
    $myDate = strtotime("+1 day", strtotime($myDate));
    $myDate = date("Y-m-d", $myDate);

     //Make sure we start a new row every week

     if ($day_count > 7)  {
         echo "</tr><tr>";
         $day_count = 1;
         }

}  // ends the while loop

 //Finaly we finish out the table with some blank details if needed

 while ( $day_count >1 && $day_count <=7 )

 {

 echo "<td> </td>";

 $day_count++;

 }


 echo "</tr></table>";

想通了,我應該使用valign =“ top”

所以

這使td內的表格與頂部對齊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM