我想显示我的html页面的正文,关于php中的条件是真还是假[即我使用if,else条件] ......
<?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>
我需要通过在html标签内的许多地方转换为“to”和“to”进行大量修改,以使echo
语句的语法正确...有没有更好的方法可以做这?? ??
答案 0 :(得分:1)
一旦写入条件,您应该关闭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>
这样,php的回声不会打扰你的报价,所以你可以将报价标准化为双倍或仅单一(我没有改变你的报价)