CSS输出php echo没有表

时间:2012-12-03 04:59:07

标签: php html css

有没有办法在不使用表的情况下使用我在PHP中回显的内容来获取excel电子表格类型的格式?

$result = mysql_query("SELECT * FROM posts"); 
while($row = mysql_fetch_array($result))
{
    echo $row['user'] . " " . $row['email'] . " " . $row['age'] . " " . $row['image'] . " " . $row['created_at'];
    echo "<br />";
}

3 个答案:

答案 0 :(得分:2)

尝试使用div。根据需要设置width

<?php
mysql_select_db("test",mysql_connect("localhost","root",""));

$result = mysql_query("select * from test");
$count = mysql_num_rows($result);
$counter = 0;
while($row = mysql_fetch_array($result))
{
    $counter++;
?>
<div style="clear:left; float:left; width:604px;<?php echo $counter == $count ? "border-bottom:1px solid black;" : ""; ?>">
    <div style="float:left; border-left:1px solid black; border-right:1px solid black; border-top:1px solid black; width:200px;"><?php echo $row['fullname'] ?></div>
    <div style="float:left; border-right:1px solid black; border-top:1px solid black; width:200px;"><?php echo $row['email'] ?></div>
    <div style="float:left; border-right:1px solid black; border-top:1px solid black; width:200px;"><?php echo $row['password'] ?></div>
</div>
<?php   
}
?>

这会给你这样的输出,
enter image description here

答案 1 :(得分:0)

使用蓝色打印CSS显示网格。

请查看http://www.blueprintcss.org/

答案 2 :(得分:0)

您可以将CSS应用于代码中嵌入了PHP的HTML元素。

示例:

<table class="style_1">
<?php
while($row = mysql_fetch_array($result))
{
?>
    <tr class="style_2">
        <td class="style3"> <? $row['user'] ?></td>
        <td class="style3"> <? $row['email'] ?></td>
        <td class="style3"> <? $row['age'] ?></td>
     </tr>

 <? } ?>