检索所选记录和分页

时间:2013-02-15 12:01:17

标签: php mysql phpmyadmin

我想分隔记录并对它们进行分页。这让我很难过。此代码显示所有记录。我想要的是;当我选择“幼儿园”时,将检索所有幼儿园水平。我继续问这个问题,我希望在这里得到解答。谢谢!

<td><b>Select Section:</b></td>
                    <td><select name="level">
                                        <option name="nursery" value="Nursery">Nursery</option>
                                        <option name="k1" value="K-1">K-1</option>
                                        <option name="k2" value="K-2">K-2</option>
                                        <option name="g1" value="Grade 1">Grade 1</option>
                                        <option name="g2" value="Grade 2">Grade 2</option>
                                        <option name="g3" value="Grade 3">Grade 3</option>
                                        <option name="g4" value="Grade 4">Grade 4</option>
                                        <option name="g5" value="Grade 5">Grade 5</option>
                                        <option name="g6" value="Grade 6">Grade 6</option>
                                        <option name="ps" value="please_select" selected="selected" id="ps">Please Select</option>
                                        </select></td>


                     <td><input type='image' name='submit' src='images/search1.jpg' id='img11' value='Search'/></td>
                     <span class='label'>&nbsp;</span>
     </tr>
    </table></div>

<table class="table1" border = "1" cellspacing="0" cellpadding="9">
<tr class="tr1">
    <th class="th1">ID Number</th>
    <th class="th1">Student Name</th>
    <th class="th1">Year Level</th>
</tr>

<?php 

        include('db.inc.php');

        if (!isset($_POST['level']))
    {
    $_POST['level'] = "undefine";
    }
    $level = $_POST['level'];



        $per_page = 3; 
        $result = mysql_query("SELECT * FROM students");
        $total_results = mysql_num_rows($result);

        $total_pages = ceil($total_results / $per_page);
        if (isset($_GET['page']) && is_numeric($_GET['page']))
        {
                $show_page = $_GET['page'];


                if ($show_page > 0 && $show_page <= $total_pages)
                {
                        $start = ($show_page -1) * $per_page;
                        $end = $start + $per_page; 
                }
                else
                {

                        $start = 0;
                        $end = $per_page; 
                }               
        }

        else
        {

                $start = 0;
                $end = $per_page; 
        }

        echo "<p><b>View Page:</b> ";

        for ($i = 1; $i <= $total_pages; $i++)
        {
                echo "<a href='master_list.php?page=$i'>$i</a> ";
        }
        echo "</p>";

        for ($i = $start; $i < $end; $i++)
        {     
                if ($i == $total_results) { break; }
                echo "<tr>";
                echo '<td>' . mysql_result($result, $i, 'id') . '</td>';
                echo '<td>' . mysql_result($result, $i, 'surname') . '</td>';
                echo '<td>' . mysql_result($result, $i, 'level') . '</td>';
                echo "</tr>"; 
        }
        echo "</table>";  
?>

0 个答案:

没有答案