如何基于php if条件创建html正文
我想在php中显示关于条件为真或假的html页面正文[即,我使用if,else条件]如何基于php if条件创建html正文,php,html,Php,Html,我想在php中显示关于条件为真或假的html页面正文[即,我使用if,else条件] <?php session_start(); if(isset($_SESSION['user'])) { echo ". Hello ".$_SESSION['user']." !"; } else { header("Location: login.php"); } ?> <html> <head> <link rel="stylesheet"
<?php
session_start();
if(isset($_SESSION['user']))
{
echo ". Hello ".$_SESSION['user']." !";
}
else
{
header("Location: login.php");
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<link href="slims.css" rel="stylesheet" type="text/css">
<title>Enter Attendance</title>
</head>
<body >
<a id="logout" href="logout.php">Logout </a>
<div id="wrapper">
<header>
<h1>Welcome to SLIMS</h1>
<nav id="mainnav">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="secselect.php" class="thispage">
attendance</a></li>
<li><a href="#">marks</a></li>
<li><a href="#">results</a></li>
<li><a href="#">others</a></li>
</ul>
</nav></header>
<div id=body>
<br/>
<?php
$num=1;
mysql_connect("localhost","root","");
mysql_select_db("attendance");
$_SESSION['tablename']=$_GET['dept']."-".$_GET['year']."-".$_GET['sec']."-".$_GET['sem'];
//echo $_SESSION['tablename'];
$_SESSION['subject']=$_GET['subject'];
$_SESSION['datepicker']=$_GET['datepicker'];
$qstr2="select * from `".$_SESSION['tablename']."-total` where date='".$_GET['datepicker']."' and subject='".$_GET['subject']."';";
//echo $qstr2;
$check=mysql_query($qstr2);
if($check)
{ echo "<font color='white' align=center face='Lucida Sans Unicode'><h2 class='centered'>Attendence for the selected date was already entered</h2></font><br><br><br><br>";
}
else
{
$qstr="select * from `".$_SESSION['tablename']."`;";
$result=mysql_query($qstr);
if(!$result)
{
echo "Invalid details selected";
}
else
{
echo '<font color="white" align=center face="Lucida Sans Unicode"><h2>Enter Attendance</h2></font>
<form method="post" action="insertatt.php" ><p align="center">
<table id="box-table-a"; >
<thead>
<tr>
<th scope="col"> Sl.No </th>
<th scope="col"> JNTU No. </th>
<th scope="col"> Name </th>
<th scope="col"> Classes </th>
</tr>
</thead>
<tbody>';
$num=1;
while($row=mysql_fetch_array($result))
{
echo "<tr><td>".$row['Sl.No']."</td>
<td>".$row["JNTU No"]."</td>
<td>".$row["Name"]."</td>
<td> <input type='radio' name='rbtn".$num."' value=1 /> 1
<input type='radio' name='rbtn".$num."' value=2 /> 2</td>
</tr>";
$num=$num+1;
}
echo "
</tbody>
</table>
<input type='submit' name='submit' value='Post Attendance' />
<input type='reset' name='reset' value='Clear Form' /></p><br><br>
</form>";
}
}?>
</div>
<footer><div id="footer">© 2013 Team 17</div>
</footer>
</div>
</body>
</html>
登记出席人数
欢迎来到SLIMS
编写条件后,应关闭PHP标记。首先,在另一个文件中或在文档顶部分离DB逻辑和其他内容:
<?php
$num=1;
mysql_connect("localhost","root","");
mysql_select_db("attendance");
$_SESSION['tablename']=$_GET['dept']."-".$_GET['year']."-".$_GET['sec']."-".$_GET['sem'];
//echo $_SESSION['tablename'];
$_SESSION['subject']=$_GET['subject'];
$_SESSION['datepicker']=$_GET['datepicker'];
$qstr2="select * from `".$_SESSION['tablename']."-total` where date='".$_GET['datepicker']."' and subject='".$_GET['subject']."';";
//echo $qstr2;
$check=mysql_query($qstr2);
$qstr="select * from `".$_SESSION['tablename']."`;";
$result=mysql_query($qstr);
?>
然后从以下条件开始:
<?php if($check): ?>
<font color='white' align=center face='Lucida Sans Unicode'><h2 class='centered'>Attendence for the selected date was already entered</h2></font><br><br><br><br>
<?php else: ?>
<?php if(!$result): ?>
<p>Invalid details selected</p>
<?php else: ?>
<font color="white" align=center face="Lucida Sans Unicode"><h2>Enter Attendance</h2></font>
<form method="post" action="insertatt.php" ><p align="center">
<table id="box-table-a"; >
<thead>
<tr>
<th scope="col"> Sl.No </th>
<th scope="col"> JNTU No. </th>
<th scope="col"> Name </th>
<th scope="col"> Classes </th>
</tr>
</thead>
<tbody>
<?php $num=1;while($row=mysql_fetch_array($result)): ?>
<tr><td><?= $row['Sl.No']; ?></td>
<td><?= $row['Name']; ?></td>
<td><input type='radio' name='rbtn<?=$num;?>' value=1 /> 1
<input type='radio' name='rbtn<?=$num;?>' value=2 /> 2</td>
</tr>
<?php $num=$num+1; ?>
<?php endwhile: ?>
</tbody>
</table>
<input type='submit' name='submit' value='Post Attendance' />
<input type='reset' name='reset' value='Clear Form' /></p><br><br>
</form>
<?php endif; ?>
<?php endif; ?>
</div>
<footer><div id="footer">© 2013 Team 17</div>
</footer>
已输入所选日期的出席人数
所选的详细信息无效
登记出席人数
序号
JNTU号。
名称
班级
&抄袭;2013年第17队
这样,php的echo就不会干扰您的报价,因此您可以将报价标准化为仅双引号或仅单引号(我没有更改您的报价)编写条件后,您应该关闭php标记。首先,在另一个文件中或在文档顶部分离DB逻辑和其他内容:
<?php
$num=1;
mysql_connect("localhost","root","");
mysql_select_db("attendance");
$_SESSION['tablename']=$_GET['dept']."-".$_GET['year']."-".$_GET['sec']."-".$_GET['sem'];
//echo $_SESSION['tablename'];
$_SESSION['subject']=$_GET['subject'];
$_SESSION['datepicker']=$_GET['datepicker'];
$qstr2="select * from `".$_SESSION['tablename']."-total` where date='".$_GET['datepicker']."' and subject='".$_GET['subject']."';";
//echo $qstr2;
$check=mysql_query($qstr2);
$qstr="select * from `".$_SESSION['tablename']."`;";
$result=mysql_query($qstr);
?>
然后从以下条件开始:
<?php if($check): ?>
<font color='white' align=center face='Lucida Sans Unicode'><h2 class='centered'>Attendence for the selected date was already entered</h2></font><br><br><br><br>
<?php else: ?>
<?php if(!$result): ?>
<p>Invalid details selected</p>
<?php else: ?>
<font color="white" align=center face="Lucida Sans Unicode"><h2>Enter Attendance</h2></font>
<form method="post" action="insertatt.php" ><p align="center">
<table id="box-table-a"; >
<thead>
<tr>
<th scope="col"> Sl.No </th>
<th scope="col"> JNTU No. </th>
<th scope="col"> Name </th>
<th scope="col"> Classes </th>
</tr>
</thead>
<tbody>
<?php $num=1;while($row=mysql_fetch_array($result)): ?>
<tr><td><?= $row['Sl.No']; ?></td>
<td><?= $row['Name']; ?></td>
<td><input type='radio' name='rbtn<?=$num;?>' value=1 /> 1
<input type='radio' name='rbtn<?=$num;?>' value=2 /> 2</td>
</tr>
<?php $num=$num+1; ?>
<?php endwhile: ?>
</tbody>
</table>
<input type='submit' name='submit' value='Post Attendance' />
<input type='reset' name='reset' value='Clear Form' /></p><br><br>
</form>
<?php endif; ?>
<?php endif; ?>
</div>
<footer><div id="footer">© 2013 Team 17</div>
</footer>
已输入所选日期的出席人数
所选的详细信息无效
登记出席人数
序号
JNTU号。
名称
班级
&抄袭;2013年第17队
这样,php的回音就不会干扰您的报价,因此您可以将报价标准化为仅双引号或仅单引号(我没有更改您的报价)您至少应该考虑使用模板引擎