0

I am printing data from database using sql query, however when i get the output i am not getting it in the desired form.

Part of the code is

$result1 = mysqli_query($con,"SELECT * FROM abc where id='".$a."'");
if (mysqli_num_rows($result1) > 0) 
{
    while($row1 = mysqli_fetch_array($result1)) 
        {
            echo "<div class='dd' style='width:600px; padding-left:15px;'>";
                echo "<div class='col-lg-3' style='font-size:medium;'>";
                    echo  $row1['name'];
                echo "</div>";
            echo "</div>";  
        }
}

output that i am getting is

q
w
e
r

however i wish to get out in the form

q  w  e
r  t  y
u  u  u

would appreciate any help

1
  • Show the generated HTML preferably in a fiddle. Commented Nov 20, 2014 at 6:05

2 Answers 2

2

Try this-
With the help of UI & LI html tag you can do... Sweet & simple code for you :)..

$result1 = mysqli_query($con,"SELECT * FROM abc where id='".$a."'");
    if (mysqli_num_rows($result1) > 0) 
    {
        echo "<div class='list'>";
        echo "<ul>";
        while($row1 = mysqli_fetch_array($result1)) {

               echo  "<li>".$row1['name']"</li>"; 
            }
       echo "</ul>";
      echo "</div>";  
    }

CSS -

div.list{
   display:block;
   width:300px;
}

div.list ui{
   width:100%;
}

div.list ui li{
   float:left;
   width:33.333%;
   list-style-type:none;
}

Demo - Fiddle

Sign up to request clarification or add additional context in comments.

Comments

0

Can be accomplished by CSS Float property , on every 4th element we clear the float

$counter = 0;

while($row1 = mysqli_fetch_array($result1)) 
{
   $counter++;

   $divstyle= 'clear:both';

   if($counter % 4 == 0){
      $divstyle= 'float:left';
   }

        echo "<div class='dd' style='width:600px; padding-left:15px;$divstyle;'>";
            echo "<div class='col-lg-3' style='font-size:medium;'>";
                echo  $row1['name'];
            echo "</div>";
        echo "</div>";  
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.