本文介绍了php寻呼机代码中的retrival sql查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我希望寻呼机在页面中显示10条记录,我发现这个很棒的代码:







my problem that I want a pager to show 10 record in page and I found this great code at:



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']。或者教师 - 电子邮件IS NULL LIMIT 。$ sf。,10)它不起作用我怀疑我的查询语法所以我下载查询构建器程序(flyspeed sql查询)并将查询构建为:选择*来自学生Where(Instructor-Email =' 。$ _SESSION ['ID']。')或(教练 - 电子邮件是空的)限制0,10但仍然无法工作

你能告诉我这是什么问题吗?非常感谢你的努力



when I retrieve table data without condition like in the code("SELECT * FROM students LIMIT ".$sf.",10";) it work but when I add an condition like ("SELECT * FROM students where Instructor-Email=". $_SESSION['ID'] ." OR Instructor-Email IS NULL LIMIT".$sf.",10") it doesn't work I was doubt my query syntax so I download query builder program (flyspeed sql query) and it built the query as:"Select * From students Where (Instructor-Email = '. $_SESSION['ID'] .') Or (Instructor-Email Is Null) LIMIT 0,10" but still didn't work
can you tell me what is the problem? with all my thanks for your efforts

推荐答案




这篇关于php寻呼机代码中的retrival sql查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 03:16