When I try to echo data from database using php my html page breaked

691

I want to make a dynamic page but when I try to echo fetched data in HTML using echo between HTML tags the page structure breaks:

This image is with php code :

This is image without php code :

<div >
<div >

  <?php while($data = mysqli_fetch_assoc($result)): ?>

  <h1 >
    <?php 
      $about = $data['content'];
      $about_intro = explode("India",$about);
      echo $about_intro[0];
    ?>
  </h1>
 <!--  <input  type="submit" value="Tell Me More"> -->
</div>
</div>

<?php endwhile; ?>
164

Answer

Solution:

Close the while loop inside thediv:

<div >
<div >

  <?php while($data = mysqli_fetch_assoc($result)): ?>

  <h1 >
    <?php 
      $about = $data['content'];
      $about_intro = explode("India",$about);
      echo $about_intro[0];
    ?>
  </h1>
  <?php endwhile; ?>
 <!--  <input  type="submit" value="Tell Me More"> -->
</div>
</div>

People are also looking for solutions to the problem: php - Redirecting from one page to another page on my website causes 404 error after using .htaccess file

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.