各位高手~目前是已經有做出分頁,但是卻只能顯示出第一頁, 當按下後面的頁數時,會出現錯誤訊息,所以印出mysql error 看到的訊息是:
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10, 10' at line 1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>Results</title>
</head>
<body>
<table>
<?php
$submit = $_POST['submit'];
$account = 'guest';
$value = '0';
// Connecting, selecting database
$link = mysql_connect('192.168.1.10', 'user', 'pwd')
or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
mysql_select_db('management') or die('Could not select database');
// Performing SQL query
$query = "SELECT count(*) FROM resulttb where id= '$account' and value= '$num' ";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$count = mysql_fetch_row($result);
$per = 10; //每頁顯示項目數量
$pages = ceil($count[0]/$per); //總頁數
for($i=1;$i<=$pages;$i++) {
echo '<a href="?page='.$i.'">' . $i . '</a>';
}
if(!isset($_GET["page"])){
$page=1; //設定起始頁
} else {
$page = intval($_GET["page"]); //確認頁數只能夠是數值資料
$page = ($page > 0) ? $page : 1; //確認頁數大於零
$page = ($pages > $page) ? $page : $pages; //確認使用者沒有輸入太神奇的數字
}
$start = ($page-1)*$per; //每頁起始資料序號
?>
<table width="450" border="1" align="center">
<tr bgcolor="#6699CC">
<th scope="col"><font size="4" face="Times New Roman, Times, serif">V1</font></th>
<th scope="col"><font size="4" face="Times New Roman, Times, serif">V2</font></th>
<th scope="col"><font size="4" face="Times New Roman, Times, serif">V3</font></th>
</tr>
<?
$result2 = mysql_query("SELECT V1,V2,V3 FROM resulttb where id= '$account' and value= '$num' LIMIT " . $start . ', ' . $per);
while(list($V1,$V2,$V3)=mysql_fetch_row($result2))
{ ?>
<tr>
<td><font size="4" face="Times New Roman, Times, serif"><? echo $V1;?></font></td>
<td><font size="4" face="Times New Roman, Times, serif"><? echo $V2;?></font></td>
<td><font size="4" face="Times New Roman, Times, serif"><? echo $V3;?></font></td>
</tr>
<?
}
?>
</table>
</body>
</html>