>  기사  >  백엔드 개발  >  javascript - PHP와 Ajax는 페이징 점프를 하지만 나올 수 없습니다. 하나님께서 살펴보실 수 있기를 바랍니다

javascript - PHP와 Ajax는 페이징 점프를 하지만 나올 수 없습니다. 하나님께서 살펴보실 수 있기를 바랍니다

WBOY
WBOY원래의
2016-12-05 13:44:111318검색

Ajax 부분 새로 고침 페이징 점프를 만들고 싶지만 왜 ajax에서 수신한 데이터가 항상 MySql ErrorNo 데이터베이스가 선택된 페이지
에 표시되는지 모르겠습니다. 그런 다음 몇 가지 테스트를 수행했습니다. 🎜> echo "111111"; echo "22222"; echo "3333" echo "4444" 만 출력됩니다! 저는 PHP를 잘 모릅니다
그래서 전문가에게 문제가 무엇인지 알아보도록 문제를 제기하고 싶습니다! 이에 대해 감사의 말씀을 전하고 싶습니다!


<code><meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<?php
if($_REQUEST['page'])
{
    $page = $_REQUEST['page'];
    $page=1;
    $cur_page = $page;
    $page -= 1;
    $per_page = 10;
    $previous_btn = true;
    $next_btn = true;
    $first_btn = true;
    $last_btn = true;
    $start = $page * $per_page;


    $conn=mysqli_connect("localhost","root","","info");
    mysqli_query($conn,"SET NAMES 'utf8'");
    **echo "44444444";**
    $query_pag_data = "SELECT id,name from content LIMIT $start, $per_page";
    $result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());
    $msg = "";
    while ($row = mysql_fetch_array($result_pag_data)) {
        $htmlmsg=htmlspecialchars($row['name']);
        $msg .= "<li><b>" . $row['id'] . "</b> " . $htmlmsg . "</li>";
    }
    $msg = "<div class='data'><ul>" . $msg . "</ul></div>"; // Content for Data

    **echo "3333333333333333333333";**
    /* --------------------------------------------- */
    $query_pag_num = "SELECT COUNT(*) AS count FROM content";
    $result_pag_num = mysql_query($query_pag_num);
    $row = mysql_fetch_array($result_pag_num);
    $count = $row['count'];
    $no_of_paginations = ceil($count / $per_page);

    **echo "2222222222";**

    /* ---------------Calculating the starting and endign values for the loop----------------------------------- */
    if ($cur_page >= 7) {
        $start_loop = $cur_page - 3;
        if ($no_of_paginations > $cur_page + 3)
            $end_loop = $cur_page + 3;
        else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
            $start_loop = $no_of_paginations - 6;
            $end_loop = $no_of_paginations;
        } else {
            $end_loop = $no_of_paginations;
        }
    } else {
        $start_loop = 1;
        if ($no_of_paginations > 7)
            $end_loop = 7;
        else
            $end_loop = $no_of_paginations;
    }
    /* ----------------------------------------------------------------------------------------------------------- */
    $msg .= "<div class='pagination'><ul>";

    // FOR ENABLING THE FIRST BUTTON
    if ($first_btn && $cur_page > 1) {
        $msg .= "<li p='1' class='active'>First</li>";
    } else if ($first_btn) {
        $msg .= "<li p='1' class='inactive'>First</li>";
    }

    // FOR ENABLING THE PREVIOUS BUTTON
    if ($previous_btn && $cur_page > 1) {
        $pre = $cur_page - 1;
        $msg .= "<li p='$pre' class='active'>Previous</li>";
    } else if ($previous_btn) {
        $msg .= "<li class='inactive'>Previous</li>";
    }
    for ($i = $start_loop; $i <= $end_loop; $i++) {

        if ($cur_page == $i)
            $msg .= "<li p='$i' style='color:#fff;background-color:#006699;' class='active'>{$i}</li>";
        else
            $msg .= "<li p='$i' class='active'>{$i}</li>";
    }

    // TO ENABLE THE NEXT BUTTON
    if ($next_btn && $cur_page < $no_of_paginations) {
        $nex = $cur_page + 1;
        $msg .= "<li p='$nex' class='active'>Next</li>";
    } else if ($next_btn) {
        $msg .= "<li class='inactive'>Next</li>";
    }

    // TO ENABLE THE END BUTTON
    if ($last_btn && $cur_page < $no_of_paginations) {
        $msg .= "<li p='$no_of_paginations' class='active'>Last</li>";
    } else if ($last_btn) {
        $msg .= "<li p='$no_of_paginations' class='inactive'>Last</li>";
    }
    $goto = "<input type='text' class='goto' size='1' style='margin-top:-1px;margin-left:60px;'/><input type='button' id='go_btn' class='go_button' value='Go'/>";
    $total_string = "<span class='total' a='$no_of_paginations'>Page <b>" . $cur_page . "</b> of <b>$no_of_paginations</b></span>";
    $msg = $msg . "</ul>" . $goto . $total_string . "</div>";  // Content for pagination
    **echo $msg;**
    **echo "1111111111111";**
}
?>
</code>
위 코드는

답글 내용:

Ajax 부분 새로 고침 페이징 점프를 만들고 싶지만 왜 ajax에서 수신한 데이터가 항상 MySql ErrorNo 데이터베이스가 선택된 페이지

에 표시되는지 모르겠습니다. 그런 다음 몇 가지 테스트를 수행했습니다. 🎜> echo "111111"; echo "22222"; echo "3333" echo "4444" 만 출력됩니다! 저는 PHP를 잘 모릅니다
그래서 전문가에게 문제가 무엇인지 알아보도록 문제를 제기하고 싶습니다! 이에 대해 감사의 말씀을 전하고 싶습니다!


위 코드는
<code><meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<?php
if($_REQUEST['page'])
{
    $page = $_REQUEST['page'];
    $page=1;
    $cur_page = $page;
    $page -= 1;
    $per_page = 10;
    $previous_btn = true;
    $next_btn = true;
    $first_btn = true;
    $last_btn = true;
    $start = $page * $per_page;


    $conn=mysqli_connect("localhost","root","","info");
    mysqli_query($conn,"SET NAMES 'utf8'");
    **echo "44444444";**
    $query_pag_data = "SELECT id,name from content LIMIT $start, $per_page";
    $result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());
    $msg = "";
    while ($row = mysql_fetch_array($result_pag_data)) {
        $htmlmsg=htmlspecialchars($row['name']);
        $msg .= "<li><b>" . $row['id'] . "</b> " . $htmlmsg . "</li>";
    }
    $msg = "<div class='data'><ul>" . $msg . "</ul></div>"; // Content for Data

    **echo "3333333333333333333333";**
    /* --------------------------------------------- */
    $query_pag_num = "SELECT COUNT(*) AS count FROM content";
    $result_pag_num = mysql_query($query_pag_num);
    $row = mysql_fetch_array($result_pag_num);
    $count = $row['count'];
    $no_of_paginations = ceil($count / $per_page);

    **echo "2222222222";**

    /* ---------------Calculating the starting and endign values for the loop----------------------------------- */
    if ($cur_page >= 7) {
        $start_loop = $cur_page - 3;
        if ($no_of_paginations > $cur_page + 3)
            $end_loop = $cur_page + 3;
        else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
            $start_loop = $no_of_paginations - 6;
            $end_loop = $no_of_paginations;
        } else {
            $end_loop = $no_of_paginations;
        }
    } else {
        $start_loop = 1;
        if ($no_of_paginations > 7)
            $end_loop = 7;
        else
            $end_loop = $no_of_paginations;
    }
    /* ----------------------------------------------------------------------------------------------------------- */
    $msg .= "<div class='pagination'><ul>";

    // FOR ENABLING THE FIRST BUTTON
    if ($first_btn && $cur_page > 1) {
        $msg .= "<li p='1' class='active'>First</li>";
    } else if ($first_btn) {
        $msg .= "<li p='1' class='inactive'>First</li>";
    }

    // FOR ENABLING THE PREVIOUS BUTTON
    if ($previous_btn && $cur_page > 1) {
        $pre = $cur_page - 1;
        $msg .= "<li p='$pre' class='active'>Previous</li>";
    } else if ($previous_btn) {
        $msg .= "<li class='inactive'>Previous</li>";
    }
    for ($i = $start_loop; $i <= $end_loop; $i++) {

        if ($cur_page == $i)
            $msg .= "<li p='$i' style='color:#fff;background-color:#006699;' class='active'>{$i}</li>";
        else
            $msg .= "<li p='$i' class='active'>{$i}</li>";
    }

    // TO ENABLE THE NEXT BUTTON
    if ($next_btn && $cur_page < $no_of_paginations) {
        $nex = $cur_page + 1;
        $msg .= "<li p='$nex' class='active'>Next</li>";
    } else if ($next_btn) {
        $msg .= "<li class='inactive'>Next</li>";
    }

    // TO ENABLE THE END BUTTON
    if ($last_btn && $cur_page < $no_of_paginations) {
        $msg .= "<li p='$no_of_paginations' class='active'>Last</li>";
    } else if ($last_btn) {
        $msg .= "<li p='$no_of_paginations' class='inactive'>Last</li>";
    }
    $goto = "<input type='text' class='goto' size='1' style='margin-top:-1px;margin-left:60px;'/><input type='button' id='go_btn' class='go_button' value='Go'/>";
    $total_string = "<span class='total' a='$no_of_paginations'>Page <b>" . $cur_page . "</b> of <b>$no_of_paginations</b></span>";
    $msg = $msg . "</ul>" . $goto . $total_string . "</div>";  // Content for pagination
    **echo $msg;**
    **echo "1111111111111";**
}
?>
</code>

문서 봐봐 얘야, 링크를 클릭해

mysqli를 사용하고 있으니 3층이 맞고 데이터베이스를 선택해, mysqli는

이거 링크에 있어 한번 봐봐 .
mysqli_select_db()
javascript - PHP와 Ajax는 페이징 점프를 하지만 나올 수 없습니다. 하나님께서 살펴보실 수 있기를 바랍니다

javascript - PHP와 Ajax는 페이징 점프를 하지만 나올 수 없습니다. 하나님께서 살펴보실 수 있기를 바랍니다

mysql과 mysqli를 혼합하세요!

위의


및 아래의 $conn=mysqli_connect("localhost","root","","info");
을 사용하세요. mysql_query($query_pag_data)

로 바꾸면 어떨까요?

<code class="php">$conn=mysql_connect("localhost","root","","info");
mysql_query($conn,"SET NAMES 'utf8'");</code>
이 오류는 데이터베이스가 선택되지 않았기 때문에 발생합니다.

는 데이터베이스입니다. 또한 위에서 언급한 것처럼 PHP는 공식적으로 포기했습니다. >확장,

또는 mysqli_query('use database')database 사용

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.