我有一个 php 页面,上面有一个 ajax 函数 makerequest(serverPage, objID),它工作正常,它有三个链接,它们也工作正常,我的内容出现在<div id=pageId>
的那个页面上。 在此页面中,第三页有一个下拉列表,由MySQL填充,其中包含On Change事件。 在此页面中,每个选项都有很多行,因此我必须决定数据通过以下方式显示在多个页面上php分页类,它也可以正常工作,但是当我单击下一页时,由于重新加载页面并在下拉列表中获取默认值,所有数据都会丢失。
一些代码内容在这里:
<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>
它工作正常我的第三页是
<?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>
显示用户功能就像这里一样
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();
}
分页代码如下所示:
<?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;
?>
我想
如果你纠正这一点,那就没问题了
while ($nt = mysql_fetch_array($result)) {
echo ('<option value="' . $nt['Id'] . '" if($State===' . $nt['Id'] . ') echo $sel; >' . $nt['state'] . '</option>');
}
像这样,
while ($nt = mysql_fetch_array($result)) {
echo "<option value='"{$nt['Id']}'"".(($State===$nt['Id'])?'selected="selected"':"") .">{$nt['state']}</option>";
}
你不能这样评估条件,嵌套echo
也不起作用。
看看前面的这个SO问题