我最近使用PHP分页教程 Pagination - what it is and how to do it 来显示MySQL数据库中的记录信息。问题是该页面只发送以最新形式发送的信息,我不太确定如何解决问题。
表单输出的代码如下所示。
$musicitems = getmusicitems($pagenumber,$prevpage,$lastpage,$nextpage);
$count = ($musicitems==NULL) ? 0 : mysql_num_rows($musicitems);
for ($i=0;$i<$count;$i++)
{
$records = mysql_fetch_assoc($musicitems);
print'
<label for="deleteMusicItem'.$records['m_id'].'" id="deleteMusicItemLabel'.$records['m_id'].'">Delete Music Record:</label>
<input type="checkbox" name="deleteMusicItem" id ="deleteMusicItem'.$records['m_id'].'" value="delete" />
<br/>
<label for="artistname'.$records['m_id'].'" id="artistLabel'.$records['m_id'].'">Artist Name:</label>
<input type="text" size="30" name="artistname" class="artistname1" id ="artistname'.$records['m_id'].'" value="'.$records['artistname'].'" />
<br/>
<label for="recordname'.$records['m_id'].'" id="recordnameLabel'.$records['m_id'].'">Record Name:</label>
<input type="text" size="30" name="recordname" class="recordname1" id ="recordname'.$records['m_id'].'" value="'.$records['recordname'].'"/>
<br/>
<label for="recordtype'.$records['m_id'].'" id="recordtypeLabel'.$records['m_id'].'">Record type:</label>
<input type="text" size="20" name="recordtype" class="recordtype1" id ="recordtype'.$records['m_id'].'" value="'.$records['recordtype'].'"/>
<br/>
<label for="format'.$records['m_id'].'" id="formatLabel'.$records['m_id'].'">Format:</label>
<input type="text" size="20" name="format" class="format1" id ="format'.$records['m_id'].'" value="'.$records['format'].'"/>
<br/>
<label for="price'.$records['m_id'].'" id="priceLabel'.$records['m_id'].'">Price:</label>
<input type="text" size="10" name="price" class="price1" id ="price'.$records['m_id'].'" value="'.$records['price'].'"/>
<br/><br/>
';
$musicfiles=getmusicfiles($records['m_id']);
for($j=0; $j<2; $j++)
{
$mus=mysql_fetch_assoc($musicfiles);
if(file_exists($mus['musicpath']))
{
echo '<a href="'.$mus['musicpath'].'">'.$mus['musicname'].'</a><br/>';
}
else
{
echo '<label for="musicFile'.$records['m_id'].'" id="musicFileLabel'.$records['m_id'].'">Music:</label> <input type="file" size="40" name="musicFile1" id="musicFile'.$records['m_id'].'"/><br/>';
}
}
$pictures=getpictures($records['m_id']);
for($j=0;$j<2;$j++)
{
$pics=mysql_fetch_assoc($pictures);
if(file_exists($pics['picturepath']))
{
echo '<img src="'.$pics['picturepath'].'" width="150" height="150"><br/>';
}
else
{
echo '<label for="pictureFile'.$records['m_id'].'" id="pictureFileLabel'.$records['m_id'].'">Picture:</label><input type="file" size="40" name="pictureFile1" id="pictureFile'.$records['m_id'].'"/><br/>';
}
}
}
echo'<input type="submit" value="Submit" name="modfiymusicitem" id="modfiymusicitem" /> ';
if ($pagenumber == 1) {
echo " FIRST PREV ";
}
else {
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=1'>FIRST</a> ";
$prevpage = $pagenumber-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=$prevpage'>PREV</a> ";
}
echo "(Page $pagenumber of $lastpage)";
if ($pagenumber == $lastpage) {
echo " NEXT LAST ";
}
else {
$nextpage = $pagenumber+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=$lastpage'>LAST</a> ";
}
答案 0 :(得分:0)
您必须手动将表单数据传递到下一页。这个最重要的部分总是被教程编写者遗忘。
您必须传递到其他页面,不仅是页码,还包括整个表单数据。
我希望您的表单使用GET方法,因此,您可以在$_SERVER['QUERY_STRING']
中将数据作为字符串或$_GET
数组。因此,您可以在regexp pagenumber
中执行QUERY_STRING
,也可以从QUERY_STRING
数组中组合另一个$_GET
,如下所示:
$_GET['pagenumber']=$nextpage;
$query_string=http_build_query($_GET);
echo " <a href='{$_SERVER['PHP_SELF']}?$query_string'>NEXT</a> ";