Chintan Mathukiya
Chintan Mathukiya

Reputation: 393

one column coming from mysql and display it in to two column in html

I get the title from database. and I want to display it in to two column. suppose in while loop print like

<tr><td>first</td><td>second</td></tr>
<tr><td>third</td><td>fourth</td></tr> 
 echo"<table border='1'>"; 
        while($row=$result->fetch_assoc())
      {
       
            echo "<tr><td>".$row['title']."</td><td>&nbsp</td></tr>";
            
      }
      echo"</table>";

Upvotes: 3

Views: 72

Answers (2)

Mooseknuckles
Mooseknuckles

Reputation: 497

 echo"<table border='1'>";

 $count = 0;

        while($row=$result->fetch_assoc())
            {

                $count ++;

                if ($count % 2 != 0) {
                    echo "<tr><td>".$row['title']."</td>";
                }

                else {
                    echo "<td>".$row['title']."</td></tr>"
                }
            }
      echo"</table>";

Upvotes: 2

Sridhar DD
Sridhar DD

Reputation: 1980

Probably you can do a work around like below.

  echo"<table border='1'>"; 
  bool first = true;
  while($row=$result->fetch_assoc())
  {
       if(first)
       {
            first = false;
            echo "<tr><td>".$row['title']."</td>";
       }
       else
       {
            echo "<td>$row['title']</td></tr>"
            first = true;
       }
  }
  echo"</table>";

Upvotes: 2

Related Questions