返回自定义模板 ,......登陆

自定义模板 ,格式化输出数据库的数据

坚果缘2019-07-11 15:46:23196
<?php

//创建PDO对象 连接数据库
$pdo = new PDO('mysql:host=127.0.0.1;dbname=sanguozhi','root','root');

//创建预处理对象
$sql = 'SELECT `w_id`,`w_name`,`force`,`arms` FROM `warriors` WHERE `healthy`=:healthy';

$stmt = $pdo->prepare($sql);

$stmt->execute([':healthy'=>1]);

//遍历
$rows = [];
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
	$rows[] = $row;
}
print_r($rows);


?>
<style>
	table,th,td{
		border:1px solid #333;
	}
	
	table{
		text-align:center;
		border:1px solid #333;
		width:50%;
		margin:30px auto;
		border-collapse:collapse;		
	}
	
	table caption{
		font-size:1.5em;
		font-weight:bolder;
		margin-bottom:15px;
	}
	
	table tr:first-chile{
		background-color:lightblue;
	}
</style>

<table>
<caption>武将资料</caption>
 <tr>
	<th>ID</th>
	<th>武将姓名</th>
	<th>武力</th>
	<th>兵种</th>
 </tr>
	<?php foreach ($rows as $row):?>
	<tr>
		<td> <?php echo $row['w_id']?></td>
		<td> <?php echo $row['w_name']?></td>
		<td> <?php echo $row['force']?></td>
		<td> <?php echo $row['arms']?></td>
	</tr>
	<?php endforeach;?>

</table>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送
  • php.cn