简体   繁体   中英

Create a table with blank squares for missing mysql data

I've written a PHP script that can populate a table in a particular way so that multiple events (or no events) can be put in one square in an HTML - similar to the layout a calendar would have. But, there's a problem, the while statement I created to fill in squares in the table when there is no data doesn't detect when there is data, and fills the entire table with empty squares. This is what the output looks like (The page is styled using Bootstrap 3). From the mysql data I have provided, these events should be in the square at {Period 1, Monday}.

Here is my data in a mysql database; mysql data

Here is a snippet of the part of the page related to this table;

<?php
$query = "SELECT * FROM configtimetabletwo WHERE term = ".$term." AND week = ".$week." ORDER BY period, day LIMIT 100;";
$results = mysqli_query($conn, $query);   
$pp=1; //The current y value of the table
$pd=0; //The current x value of the table 
echo '<tr><td>';
while($row = mysqli_fetch_row($results)) {
while((pd!=$row[3] or $pp!=$row[4]) and $pp<6){ //This while statement fills in empty squares and numbers each row.
if($pd==0)  {
            echo $pp."</td><td>";
            $pd++;
            }
elseif($pd<5){
            echo "</td><td>";
            $pd++;
             }
else    {
            echo "</td></tr><tr><td>";
            $pd=0;
            $pp++;
        }
    }
    echo '<a href="?edit='.$row[0].'" class="label label-default">';
    echo $row[5].' '.$row[6].' - '.$row[7]."</a><br>";
}
echo "</td></tr></table>"
?>

I haven't been able to figure out why this happens so far, thanks in advance to anyone who has any idea what's going on.

In the comments below my question, pavlovich pointed out the error. In this case, it was simply an issue of forgetting to use a $ to reference a variable . It would seem that this doesn't throw an error in a while statement like it would elsewhere.

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