Page 517 - Computer_Science_F5
P. 517

Computer Science  Then, embed the PHP code within the HTML file to display the dynamic content as
           shown in Program Example 8.5:

                   Program Example 8.5:

            PHP program to embed the PHP code within the HTML file to display the
          FOR ONLINE READING ONLY
            dynamic content


              <!DOCTYPE html>
              <html>
              <head>
                  <title>Farming Crops</title>
                  <style>
                      /* CSS styles */
                      .crop {
                          border: 1px solid #ccc;
                          padding: 10px;
                          margin: 10px;
                          display: inline-block;
                      }
                  </style>
              </head>
              <body>
                  <h1>Farming Crops</h1>
                  <div class=”crop-gallery”>
                      <?php
                      // Display data fetched from the farming database
                      while($row = $result->fetch_assoc()) {
                          echo ‘<div class=”crop”>’;
                          echo ‘<img src=”’ . $row[“image_url”] . ‘” alt=”’ . $row[“description”] . ‘”>’;
                          echo ‘<h3>’ . $row[“crop_name”] . ‘</h3>’;
                          echo ‘<p>’ . $row[“harvest_season”] . ‘</p>’;
                          echo ‘</div>’;
                      }
                      ?>
                  </div>
              </body>
              </html>


                                                 508
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   508                                                     23/07/2024   12:35
   512   513   514   515   516   517   518   519   520   521   522