我有一个mysqli数据库,里面有标记表和人员表。
在网页上,我显示了今年人们的记录列表:
SELECT * FROM markers m, people p WHERE m.MarkerID = p.MarkerID and p.Publish=1 and year(m.date) like '2015'
当您从列表中单击某个人时,您将获得一个新的网页,该网页在php中使用此查询显示该人的数据:
$name = $_POST['name'];
$newname = str_replace("_", " ", $name);
$q = "SELECT * FROM people p, markers m where p.MarkerID = m.MarkerID and p.Name = '" . $newname . "'";
在页面底部是箭头,您可以单击下一条记录和最后一条记录。
请问如何检索下一张或最后一张唱片?下一条记录将是从第一个查询开始按日期到来的记录;先前的记录将是第一次查询之前的日期记录。
答案 0 :(得分:1)
目前尚未经过测试。
让我知道你的想法,提出任何问题。
$recs = 20; // number of records per page
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM markers m, people p WHERE m.MarkerID = p.MarkerID and p.Publish=1 and year(m.date) like '2015'";
$next = intval($_POST['next']);
$last = intval($_POST['last']);
if($last > 0){
$limit1 = $last - $recs;
$limit2 = $last + 1;
}
else{
$limit1 = $next;
$limit2 = $limit1 + $recs;
}
$query = "$sql LIMIT $limit1 $limit2";
$results = mysqli_query($link,$sql);
// do your existing page
$rows = mysql_num_rows($results);
if($rows == $recs)
$result = mysqli_query($link,"SELECT FOUND_ROWS()");
$more = mysqli_fetch_array($result , MYSQL_NUM);
}
$remaining = intval($more[0]);
$total = $remaining + $limit2;
$remaining -= ($limit1 + $recs);
$next += $recs + 1;
if($remaining > 0)
echo <<<EOF
<form action="#' method="post">
<input type="hidden" name="next" value="$next"/>
<button type="submit">Next</button>
</form>
<form action="#' method="post">
<input type="hidden" name="last" value="$total"/>
<button type="submit">Last</button>
</form>
EOF;
}
答案 1 :(得分:1)
我认为这可以用于事先记录:
$q = "select * from people v, markers m
where v.Publish = 1
and m.MarkerID = v.MarkerID
and m.date = (select max(m.date)
from markers m, victims v where m.MarkerID = v.MarkerID
and v.Publish = 1
and m.date < '" . $this_date . "')"