HTML formu doğru veri, PHP sayfalama göndermiyor

1 Cevap php

Geçenlerde bir PHP pagination öğretici, Pagination - what it is and how to do it , to display record information from a MySQL veritabanı kullandık. Sorun sayfasında sadece son şeklinde gönderilen bilgi gönderir ve ben sorunu çözmek için nasıl emin değilim olmasıdır.

Form çıktı için kod aşağıda gösterilmiştir.

$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> ";
}

1 Cevap

Elle sonraki sayfaya form verilerini geçmek zorunda. Bu, en önemli kısmı, her zaman öğretici yazarlar tarafından unutulur.

You have to pass to other pages, not only the page number, but the whole form data. I hope your form uses the GET method, as it should be, so, you have your data either in the $_SERVER['QUERY_STRING'] as a string or the $_GET array. So, you can either do regexp pagenumber in the QUERY_STRING, or assemble another QUERY_STRING from the $_GET array, like this:

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