php连接了数据库 从数据库中提取一系列的数据 怎么样在网页中能自动形成表格形式
2012-06-19 · 知道合伙人软件行家
<?php
header('Content-type:text/html;charset=utf-8');
$db = new mysqli('localhost','root','root','books');
$rows = $db->query('SELECT * FROM customers');
echo '<table border="1"><tr><td>姓名</td><td>年龄</td></tr>';
while($row = $rows->fetch_assoc()){
echo '<tr><td>'.$row['name'].'</td>';
echo '<td>'.$row['address'].'</td></tr>';
}
?>
<table>
<?php
$array = array(1, 2, 3, 4, 5, 6, 7);
foreach ($array as $value) {
?>
<tr>
<td><?php echo $value; ?></td>
</tr>
<?php
}
?>
</table>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#c0de98" onmouseover="changeto()" onmouseout="changeback()">
<tr>
<td width="3%" height="26" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">选择</div></td>
<td width="5%" height="18" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">编号</div></td>
<td width="24%" height="18" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">文章标题</div></td>
<td width="10%" height="18" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">ip/pv</div></td>
<td width="17%" height="18" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">添加时间</div></td>
<td width="17%" height="18" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2">修改时间</div></td>
<td width="7%" height="18" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2">编辑</div></td>
<td width="7%" height="18" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2">删除</div></td>
</tr>
<?php
$act = new article();
$acrs = $act->Query();
$num = mssql_num_rows($acrs);//总记录数
for($i=0;$i<$num;$i++)
{
$myrow=mssql_fetch_array($acrs);
?>
<tr>
<td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE1">
<input name="checkbox" type="checkbox" class="STYLE2" value="checkbox" />
</div></td>
<td height="18" bgcolor="#FFFFFF" class="STYLE2"><div align="center" class="STYLE2 STYLE1"><?php echo $myrow["id"]?></div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE2 STYLE1"><?php echo $myrow["title"]?></div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE2 STYLE1"><?php echo $myrow["ip"]."/".$myrow["hit"]?></div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE2 STYLE1"><?php echo $myrow["time"]?></div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center" ><a href="#"><?php echo $myrow["edit_time"]?></a></div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center"><img src="images/037.gif" width="9" height="9" /><span class="STYLE1"> [</span><a href="#">编辑</a><span class="STYLE1">]</span></div></td>
<td height="18" bgcolor="#FFFFFF"><div align="center"><span class="STYLE2"><img src="images/010.gif" width="9" height="9" /> </span><span class="STYLE1">[</span><a href="#">删除</a><span class="STYLE1">]</span></div></td>
</tr>
<?php }?>
</table>