0

私の問題は、ページに 10 件のレコードのみを表示したいということです。phpjabbersでこの素晴らしいコードを見つけました。

    Host = "localhost"
    user="root"
    password=""(Nothing)

<?php
    $con = mysql_connect("localhost","root","") or die("Unable to connect");
    $db = mysql_select_db("test",$con) or die("Unable to select DB");

    if(isset($_GET['page']))
    {
        $page = $_GET['page'];
    }
    else
    {
        $page = 1;
    }

    $sf = ($page-1) * 10;
    $sql = "SELECT * FROM students LIMIT ".$sf.",10";
    $rs = mysql_query($sql,$con);
    //echo $rs;
    ?>
    <html>
    <head>
            <title>Pages</title>
    </head>
    <body>
        <?php
            $sql1 = "SELECT COUNT(name) FROM students";
            $rs1 = mysql_query($sql1,$con);
            $row1 = mysql_fetch_row($rs1);
            $total = $row1[0];
            $tp = ceil($total/10);

            for($i = 1; $i <= $tp; $i++)
            {
                echo "<a href='test.php?page=".$i."'>".$i."</a> ";
            }
        ?>
        <table>
            <tr>
                <th>Name</th>
                <th>Phone Number</th>
            </tr>
            <?php
                while($row = mysql_fetch_assoc($rs))
                {
            ?>
            <tr>
                <td><?php echo $row['name']; ?></td>
                <td><?php echo $row['ph_no']; ?></td>
            </tr>
            <?php
                }
            ?>
        </table>
        <?php
            $sql1 = "SELECT COUNT(name) FROM students";
            $rs1 = mysql_query($sql1,$con);
            $row1 = mysql_fetch_row($rs1);
            $total = $row1[0];
            $tp = ceil($total/10);

            for($i = 1; $i <= $tp; $i++)
            {
            echo "<a href='test.php?page=".$i."'>".$i."</a> ";
            }
        ?>
    </body>
</html>

コードのように条件なしでテーブルデータを取得すると:

"SELECT * FROM students LIMIT ".$sf.",10";

それは機能しますが、次のような条件を追加すると:

"SELECT * FROM `students` where `Instructor-Email`=". $_SESSION['ID'] ." OR `Instructor-Email` IS NULL LIMIT".$sf.",10"

うまくいきません。

クエリ構文に疑問があるため、クエリ ビルダー プログラム (flyspeed sql query) をダウンロードし、クエリを次のように作成しました。

"Select * From students Where (`Instructor-Email` = '. $_SESSION['ID'] .') Or (`Instructor-Email` Is Null) LIMIT 0,10" 

それでもうまくいきませんでした!

何が問題なのか教えていただけますか?あなたの努力に感謝します。

4

2 に答える 2