jeudi 2 avril 2020

I want to fill an HTML Table with information i get with a PHP if sentence

So i'm creating a timetable for my school and i can't figure out how to fill in an HTML table with the data i get from my PHP IF/ELSE/WHILE combination. This combination looks like this :

if(isset($_POST['gomb'])){
$timex = 1;
$timeid =0;
 While ($weekx < $weekendx) {
     $timex = 1;

      While ($timex <= 4) {
            $osztaly1 = "SELECT* FROM timetable where ((class = '$classx') and (dateq = '$weekx') and (timeq = '$timex'))";    
            $result1 = mysqli_query($MySqliLink,$osztaly1) OR die("MySqli hiba (" .mysqli_errno($MySqliLink). "): " . mysqli_error($MySqliLink));
            //----------------------------
                $subjectfr = null;
                $optionsfr = null;
                $timeqfr = null;
                $dateqfr = null;
                $timeid =  null;
            while($row = mysqli_fetch_array($result1)){
                $subjectfr = $row['subject'];
                $optionsfr = $row['options'];
                $timeqfr = $row['timeq'];        
                $dateqfr = $row['dateq'];
            }

            $sajat = "SELECT* FROM timetable where ((teacher = '$teacherx') and (dateq = '$weekx') and (timeq = '$timex'))";    
            $sajat1 = mysqli_query($MySqliLink,$sajat) OR die("MySqli hiba (" .mysqli_errno($MySqliLink). "): " . mysqli_error($MySqliLink));
            $teacherfr =  null;
            while($row = mysqli_fetch_array($sajat1)){
                $teacherfr = $row['teacher'];
            }
            if ($timex != $timeqfr) {
                if ($teacherfr != $teacherx) {
                    echo '<button class="free">szabad</button>';
                    $timex++;
                    $timeid++;
                }else{
                    echo '<button class="reserved">FOGLALT</button>';
                    $timex++;
                    $timeid++;
                }

            }
            else{
                if ($optionsfr != 1 && $optionsfr == $optionx) {
                if ($teacherfr != $teacherx) {
                    echo '<button class="free">SZABAD</button>';
                    $timex++;
                    $timeid++;
                }else{
                    echo '<button class="reserved">FOGLALT</button>';
                    $timex++;
                    $timeid++;
                }
                }
                else{
                    echo '<button class="reserved">FOGLALT</button>';
                $timex++;
                $timeid++;
                }
                }

      }
      $weekx = $weekx+86400;
      echo '<br>';


    }

}

And it creates an output like this: output of code. And i have a table wrriten in HTML which looks like: table So the data i want to put in the table is when you look at the picture: the outputs first row goes in the tables first column. Because the things are in hungarian here's some translation: "ebédszünet" = lunch break, "szabad" means free, so that time is free and the teacher can put a class there, and "foglalt" means not free. Also my variables are if there's an x in the end it's the data we want to upload into the database using a select box form (subject, class, etc..) if it has FR in the end it means it's the data we asked down from the server (already existing classes) I think that's all the necessary information, if i left something out feel free to ask! :)

Aucun commentaire:

Enregistrer un commentaire