嗨我有一个系统,我只想显示MYSQL的最后300条记录,通常我只会写这样的查询LIMIT 300
我遇到的问题是我正在使用一个分页系统来编写这样的查询。
$tableName="masterip_details";
$targetpage ="raw_data.php";
$limit = 30;
$query = "SELECT COUNT(*) as num FROM $tableName where type='6' AND country_code='GB'";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
// Get page data
$query1 = "SELECT * FROM $tableName where type='6' AND country_code='GB' LIMIT $start, $limit";
$result = mysql_query($query1);
问题是因为它使用限制来计算开始和结束页码我不确定我是否可以限制在使用分页时返回的行数。
答案 0 :(得分:0)
select * from (SELECT * FROM $tableName where type='6' AND country_code='GB' order by AUTO_INCERMENT_ID DESC LIMIT 300) as a order by AUTO_INCERMENT_ID ASC LIMIT $start, $limit