简体   繁体   中英

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

I have a calendar I created for a bottling schedule. You can drag and drop items from one data to another and it updates the database. This part works fine.

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

However, for some reason, the headers "sometimes" don't line up properly when they have data in them. They will be down somewhere between .5 to 1 table cell below where they should be. I'm sure it's just something bone headed, but I can't figure it out.

Any help is appreciated.

The what I think is offending part of the code is here:

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

The complete code is probably not needed, but I included it for completeness sake.

<?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>";

Figured it out, I should be using valign = "top"

so

This makes the table inside the td align to the top

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM