Skip to content
Advertisement

I have a single div and it needs to be duplicated dynamically

I have a single div and a unknown number(say n) of rows of data. i need to show that data on my html cards and these cards are to be generated dynamically by the output value(n).

say if i have 10 rows of data.my div element needs to be created 10 times and each row data is to be displayed on each div

by the way i am using PHP for backend.

here is my codes This is my div

<div class="row">
  <div class="column">
    <div class="card">
      <h1><?php echo"$value"; ?></h1>
      <h3><?php<?php echo"$description";?></h3>
    </div>
  </div>
</div>

and this is my php code

<?php
      $conn=new mysqli("localhost","root","","programmingpioneers");
          if(!$conn)
          {
            echo "connection_failed";
          }
          else{
            //echo "sucess";
          }
          $query= "select title,description from problems where difficulty='hard'";
          $result=mysqli_query($conn,$query);
          $row=mysqli_fetch_array($result);
          if (mysqli_query($conn, $query)) 
          {
              echo "sucess<br>";
              while ($row=mysqli_fetch_array($result)) {
                       $title=$row[0];
                   $description=$row[1];
                   echo "$title <br> $description";
                }


           }

  else {
        echo "Error: " . $query . "<br>" . mysqli_error($conn);
    }
         ?>

if i try to but my div inside

echo"$title <br>$description";

it is throwing the following error

Parse error: syntax error, unexpected 'row' (T_STRING), expecting ';' or ',' in C:xampphtdocsmyappuseless.php on line 19

Advertisement

Answer

Use loop in the div you want to have again and again.Please check the code if it works for you.

enter image description here

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement