简体   繁体   中英

how to set pagination on a lot of data rows after selection a option from the dropdown list with onchange event in php

I have a php page on which has a ajax function makerequest(serverPage, objID) , it works fine it has three links they also works fine my content comes on that page in the <div id=pageId> . in this page the third page has a dropdown list populated by mysql with on change event. in this page a lot of rows on every option so I have to decide that the data show on multiple page by php pagination class,it also works fine, but when I click on next page all the data lost due to reload the page and get the default value in the dropdown list.

Some of code content is here:

<div id="menu">
    <!-- <a href="?id=AllIndiaengineringCollege" What part we want to link to onClick="makerequest('page.php?id=AllIndiaengineringCollege', 'content'); return false;" For AJAX - Load page into the div>AllIndiaengineringCollege</a>-->
    <a href="?id=AllIndiaengineringCollege" onClick="makerequest('id=AllIndiaengineringCollege', 'content'); return false;" style="text-decoration:none;color: #3E5AAB" >All India Engineering College</a>
    <a href="?id=Deemed" onClick="makerequest('page.php?id=Deemed', 'content'); return false;" style="text-decoration:none;color: #3E5AAB">Deemed Universities</a>
    <a href="?id=state" onClick="makerequest('id=state', 'content'); return false;" style="text-decoration:none;color: #3E5AAB">State Engineering College</a>
</div>

</font></div>
<div id='content'style="text-align:left;width:897px; height:auto; background-color:#99CCFF;padding:1px">
    <?PHP
    if (isset($_GET['id'])) {
        $pageId = $_GET['id'];
        if ($pageId == 'AllIndiaengineringCollege') {
            include("/pagination/index.php");
        }
        if ($pageId == 'Deemed') {
            include("/pagination/state.php");
        }
        if ($pageId == 'state') {
            include("/pagination/state.php");
        }
    }
    ?>
</div>

it works fine my third page is

<?php
$result = mysql_query("SELECT Id,state FROM state");
echo "<select name=State id='Id' class='select' onchange='showUser(this.value)'>";
while ($nt = mysql_fetch_array($result)) {
    echo ('<option value="' . $nt['Id'] . '" if($State===' . $nt['Id'] . ') echo $sel; >' . $nt['state'] . '</option>');
}
echo "</select>";
?> 
</div>
        <div id="state"><b><center>xxxxxxxx.</center></b>

showUser function is like here

function showUser(str) {
    if (str == "") {
        document.getElementById("state").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("state").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "pagination/statelist.php?state=" + str, false);
    xmlhttp.send();
}

And the pagination code is like here:

<?php
include('db.php');
include('function.php');

$q          = $_GET["state"];
$page       = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit      = 2;
$statement  = "college where State= '" . $q . "'";
$url        = "BTech.php?id=state&State=" . $q . "&";
$startpoint = ($page * $limit) - $limit;
?>

I think if you corrected this, it would be fine

while ($nt = mysql_fetch_array($result)) {
    echo ('<option value="' . $nt['Id'] . '" if($State===' . $nt['Id'] . ') echo $sel; >' . $nt['state'] . '</option>');
}

as something like this,

while ($nt = mysql_fetch_array($result)) {
    echo "<option value=\"{$nt['Id']}\"".(($State===$nt['Id'])?'selected="selected"':"") .">{$nt['state']}</option>";
}

You can't evaluate conditions that way, nested echo wont work either.

Look at this previous SO question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM