2010-03-05 78 views
1

我最近使用了PHP分頁教程,Pagination - what it is and how to do it,顯示來自MySQL數據庫的記錄信息。問題是該頁面只發送以最新形式發送的信息,而我不太清楚如何解決該問題。HTML表格不能發送正確的數據,PHP分頁

表單輸出的代碼如下所示。

$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

您必須手動將表單數據傳遞到下一頁。這個最重要的部分總是被教程作者遺忘。

您必須傳遞給其他頁面,而不僅僅是頁碼,而是整個表單數據。 我希望您的表單使用GET方法,因爲它應該是這樣的,因此,您將數據作爲字符串存儲在$_SERVER['QUERY_STRING']$_GET陣列中。所以,你可以從$_GET陣列做regexp pagenumberQUERY_STRING,或組裝另一QUERY_STRING,像這樣:

$_GET['pagenumber']=$nextpage; 
$query_string=http_build_query($_GET); 
echo " <a href='{$_SERVER['PHP_SELF']}?$query_string'>NEXT</a> ";