我的问题是我想要一个页面只显示 10 条记录,我在phpjabbers找到了这个很棒的代码:
Host = "localhost"
user="root"
password=""(Nothing)
<?php
$con = mysql_connect("localhost","root","") or die("Unable to connect");
$db = mysql_select_db("test",$con) or die("Unable to select DB");
if(isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$sf = ($page-1) * 10;
$sql = "SELECT * FROM students LIMIT ".$sf.",10";
$rs = mysql_query($sql,$con);
//echo $rs;
?>
<html>
<head>
<title>Pages</title>
</head>
<body>
<?php
$sql1 = "SELECT COUNT(name) FROM students";
$rs1 = mysql_query($sql1,$con);
$row1 = mysql_fetch_row($rs1);
$total = $row1[0];
$tp = ceil($total/10);
for($i = 1; $i <= $tp; $i++)
{
echo "<a href='test.php?page=".$i."'>".$i."</a> ";
}
?>
<table>
<tr>
<th>Name</th>
<th>Phone Number</th>
</tr>
<?php
while($row = mysql_fetch_assoc($rs))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['ph_no']; ?></td>
</tr>
<?php
}
?>
</table>
<?php
$sql1 = "SELECT COUNT(name) FROM students";
$rs1 = mysql_query($sql1,$con);
$row1 = mysql_fetch_row($rs1);
$total = $row1[0];
$tp = ceil($total/10);
for($i = 1; $i <= $tp; $i++)
{
echo "<a href='test.php?page=".$i."'>".$i."</a> ";
}
?>
</body>
</html>
当我在没有条件的情况下检索表数据时,如代码中:
"SELECT * FROM students LIMIT ".$sf.",10";
它有效,但是当我添加如下条件时:
"SELECT * FROM `students` where `Instructor-Email`=". $_SESSION['ID'] ." OR `Instructor-Email` IS NULL LIMIT".$sf.",10"
它不起作用。
我怀疑我的查询语法,所以我下载了查询生成器程序(flyspeed sql 查询)并将查询构建为:
"Select * From students Where (`Instructor-Email` = '. $_SESSION['ID'] .') Or (`Instructor-Email` Is Null) LIMIT 0,10"
但仍然没有工作!
你能告诉我有什么问题吗?感谢您的努力。