How to align 2 while result per line

Asked

Viewed 35 times

1

How can I make the Divs contained in the loop list 2 per line instead of listing one at the bottom of the other

Lowlife

$sql = "SELECT * FROM aparelhos  ";
$resultado = mysql_query($sql) or die( mysql_error());
while ($row = mysql_fetch_assoc($resultado)) {
$nome = $row['nome'];
<div><?echo $nome?></div>
}

//como normalmente e visualizado
Fulano de Tal
Maria Fulana
Home Simpson
Lisa Simpson

//como queria que visualiza-se
Fulano de Tal             Maria Fulana
Homer Simpson             Lisa Simpson
....                      ....

1 answer

3


This is a matter of page formatting. Style! So you should really use CSS.

You can make your <div></div> side by side:

div{
  width: 49%;
  border: 1px solid red;
  float: left;
}

If you don’t want to occupy the width of <body></body> completely, define a parent element DIV outside the loop (loop) while and set the maximum width you want to use when printing data side by side by PHP.

Reference to the attribute float here.

See CSS in action: fiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.