0
点赞
收藏
分享

微信扫一扫

PHP酒店管理demo案例(数组遍历)


PHP酒店管理demo案例(数组遍历)

目录

PHP酒店管理demo案例(数组遍历)

PHP酒店管理前台编码:

PHP酒店管理后台编码:

执行效果:

点击入住测试:

退房测试:

源码地址:

PHP酒店管理前台编码:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
</head>

<body>
<style>
* {
margin: 0px auto;
padding: 0px;
}
</style>
<div style="width: 50%;">
<form action="index.php" method="get">
<p>
<input type="text" name="houseName" placeholder="请输入酒店名称" class="form-control">
</p>
<p>
<input type="text" name="nums" placeholder="请输入楼层数" class="form-control">
</p>
<p>
<input type="text" name="count" placeholder="请输入每层房间数量(10以内)" class="form-control">
</p>
<p>
<input type="submit" value="创建酒店" class="btn btn-block btn-primary">
</p>
</form>
</div>
</body>

</html>

PHP酒店管理后台编码:

<?php
#酒店名称
$houseName=$_GET["houseName"];
#酒店层数
$nums=$_GET["nums"];
#酒店每层数量
$count=$_GET["count"];
$arr=array();
for ($i=0; $i < $nums; $i++) {
for ($j=0; $j < $count; $j++) {
$arr[$i][$j]=($i+1)."层".($j+1)."室";
}
}
echo "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>";
echo "<h1 align='center'>".$houseName."</h1>";
echo "<table class='table table-hover table-bordered'>";
$i=0;
foreach ($arr as $value) {
$i++;
$j=0;
echo "<tr align='center'>";
foreach ($value as $val) {
$j++;
echo "<td><button class='btn btn-primary' id='b_".$i."_".$j."' onclick='updateIt(".$i.",".$j.")'>".$val."</button></td>";
}
echo "</tr>";
}
echo "</table>";
?>
<script>
function updateIt(o,p){
if(!confirm('是否入住?')){
return;
}
var but=document.getElementById("b_"+o+"_"+p);
if(but.innerHTML=="已入住"){
but.innerHTML=o+"层"+p+"室";
}else{
but.innerHTML="已入住";
}

}
</script>

执行效果:

PHP酒店管理demo案例(数组遍历)_html

 点击入住测试:

PHP酒店管理demo案例(数组遍历)_php_02

退房测试:

PHP酒店管理demo案例(数组遍历)_html_03

还原:

PHP酒店管理demo案例(数组遍历)_css_04

完结。

源码地址:

【php酒店管理_案例.rar-教育文档类资源】


举报

相关推荐

0 条评论