bootstrap css data load

351 views Asked by At

i am using bootstrap framework for college project

i have data 50+

<div class="span12">
   <div class="span4">
         --- data ---
   </div>

<div class="span4">
         --- data ---
   </div>

<div class="span4">
         --- data ---
   </div>

</div>

i want that every row only 3 data. after three data it will create new row ie new

<div class="span12">

i am not able to do it dynamically plz help.

i tried this but didnt worked

if(mysql_num_rows($country)>0)
   {
  while($row=mysql_fetch_array($country))
 {
      $c=0;
      echo "<div class='span12'>";

   if($c==0 || $c==1 || $c==2)
  {
      echo "<div class='span4'>".$row['countryName']."</div>";
      $c++;
   }
   else
   {
     echo "</div>";
   }
 }

}

2

There are 2 answers

0
21Canadians On BEST ANSWER
if(mysql_num_rows($country)>0)
   {
  while($row=mysql_fetch_array($country))
 {
      $c=0;
      echo "<div class='span12'>";

   if($c==0 || $c==1 || $c==2)
  {
      echo "<div class='span4'>".$row['countryName']."</div>";
      $c++;
   }
   else
   {
     echo "</div>";
   }
 }

} 

You are setting $c back to 0 everytime. Try my below code:

    if(mysql_num_rows($country)>0)
       {
$c=0;
          echo "<div class='span12'>";
      while($row=mysql_fetch_array($country))
     {
          $c++;

       if($c % 3)
      {
 echo "<div class='span4'>".$row['countryName']."</div>";
          $c++;
       }
       else
       {
          echo "<div class='span4'>".$row['countryName']."</div>";
          $c++;
         echo "</div>";
       }
     }

    } 
0
Vad.Gut On

i think that this logic will work much better

$row_num = mysql_num_rows($country);
if($row_num > 0)
{
    for ($i=0; $row = mysql_fetch_array($country); $i++)
    {
        $res_array[$i] = $row;
    }

    $i--;
    while($i > 3)
    {
        echo "<div class='span12'>";
        echo "<div class='span4'>". $row[$i]['countryName'] ."</div>";
        echo "<div class='span4'>". $row[$i+1]['countryName'] ."</div>";
        echo "<div class='span4'>". $row[$i+2]['countryName'] ."</div>";
        echo "</div>";
        $row_num += 3;      
    }

    echo "<div class='span12'>";
    if ($i > 0) 
    {
        echo "<div class='span12'>";
        echo "<div class='span4'>". $row[$i]['countryName'] ."</div>";
        $i--;
        if ($i > 0) 
        {
            echo "<div class='span4'>". $row[$i]['countryName'] ."</div>";
        }
        echo "</div>";
    }
}

Good luck