<html> <head> <meta charset="UTF-8"></head> <script type="text/javascript" src="http://localhost/jquery.js" ></script><script type="text/javascript" > function aurl(i){ var url = window.location.href; if(url.indexOf('?')>0){ url=url.substring(0,url.indexOf('?')) ;} url=url+"?page="+i; document.getElementById("documentForm").action=url; document.getElementById("insu").click(); }</script><body > <form id="documentForm" method="POST"> <p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" /> </p> <p> <input type="submit" name="submit" id="insu" value="搜索!"/> </p> </form> <?php$key = $_POST["key"]; if($key==""){ echo "请输入搜索条件"; return;}//取得页码$page = @$_GET['page'];//定义每页显示信息条数$page_size = 10;//当页码参数为空时,将页码设为1if ($page == ""){ $page = 1;}$wsdl="http://pica.chalwin.com/service/JsAccessWebService.asmx?wsdl";$client = new SoapClient($wsdl);$param = array('NodeId'=>'1','key'=>$key,'pageIndex'=>$page,'pageSize'=>$page_size);//传参$ret = $client->NewsSearch($param);//执行获取新闻的方法//print_r ($ret);if(isset($ret)&&$ret){ foreach($ret->NewsSearchResult->InheritanceNews as $item) { echo "\n<table border=1 cellspacing='0' width='30%'>\n<tr>"; echo "<td>$item->Title</td>\n"; echo "</tr>"; }} else { echo 'no user'; } //总页数 $totalPage = ceil(($item->NewsCount)/$page_size); //上一页链接 $Prev = $page - 1; if ($Prev < 1) { $Prev = 1; } //下一页链接 $Next = $page + 1; if ($Next > $totalPage) { $Next = $totalPage; } //输出上一页链接 if ($page <> 1) { echo '<span><a href="javascript:aurl(1)">First </a></span>'; echo '<span><a href="javascript:aurl(' . $Prev . ')">Prev</a></span>'; } else { echo '<span>First</span>'; echo '<span>Prev</span>'; } //页码数字链接 //显示的数字个数 $pageNumber = 5; //页码数算法 $pagebegin = $page - $pageNumber; if ($page == 1) { $pageend = $pageNumber; } else { $pageend = $page + $pageNumber; } if ($pagebegin <= 0) { $pagebegin = 1; } if ($pageend > $totalPage) { $pageend = $totalPage; } //一次向前翻$pageNumber行 if ($page > $pageNumber) { echo '<span><a href="javascript:aurl('. ($page - $pageNumber) . ')"><<</a></span>'; } //输出动态生成的页码链接 for ($i = $pagebegin; $i <= $pageend; $i++) { if ($i == $page) { echo '<span style="background:#FFCC99">' . $i . '</span>'; } else { echo '<span><a href="javascript:aurl('. $i . ')">' . $i . '</a></span>'; } } //一次向后翻$pageNumber行 if (($totalPage - $page) > 5) { echo '<span><a href="javascript:aurl('. ($page + $pageNumber) . ')">>></a></span>'; } //输出下一页链接 if ($page <> $totalPage) { echo '<span><a href="javascript:aurl('. $Next .')">Next</a></span>'; echo '<span><a href="javascript:aurl('. $totalPage .')">Last</a></span>'; } else { echo '<span>Next</span>'; echo '<span>Last</span>'; } ?></body> </html>
有没有人啊
foreach循环最后少加上了一个吧
网上有分页的类,下一个看看
foreach循环最后少加上了一个吧
是的,这里确实少了一个,感谢哈
网上有分页的类,下一个看看
初学者,你不知道啊,太复杂的看起来打都看不懂。
还有人吗?剩下的2个问题都是头大问题
if($key==""){ echo "请输入搜索条件"; return; $_SESSION['key'] = $key;//这里把KEY保存到session}<p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" /><?=$_SESSION[key] ?> </p>
if($key==""){ echo "请输入搜索条件"; return; $_SESSION['key'] = $key;//这里把KEY保存到session}<p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" /><?=$_SESSION[key] ?> </p>
if($key==""){ echo "请输入搜索条件"; return; $_SESSION['key'] = $key;//这里把KEY保存到session}<p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" /><?=$_SESSION[key] ?> </p>
if($key==""){ echo "请输入搜索条件"; return; $_SESSION['key'] = $key;//这里把KEY保存到session}<p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" /><?=$_SESSION[key] ?> </p>
<form id="documentForm" method="POST"> <p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" value="<?=$_SESSION[key] ?>"/> </p> <p> <input type="submit" name="submit" id="insu" value="搜索!"/> </p> </form>
果然还是迷糊了。应该写在else里面,如果$key不为空再写进session。
"/>
加上引号
我再看看第三个
首先,这里你得明白一个原理:url带参数过来的是GET提交的,需要用$_GET接收数据
还有,分页的时候链接需要把所有参数传递过去,比如你这里的就应该把key这个参数传递过去,即形式如:
a.php?key=$key&page=2 这样的格式
最后一点:$key = $_POST["key"]; 要改成$key = ($_POST["key"]=='')? $_GET["key"]:$_POST["key"];
最后用下面这个放在你的input里
"/>
果然还是迷糊了。应该写在else里面,如果$key不为空再写进session。
"/>
加上引号
我再看看第三个
加上引号还是有错哦。
首先,这里你得明白一个原理:url带参数过来的是GET提交的,需要用$_GET接收数据
还有,分页的时候链接需要把所有参数传递过去,比如你这里的就应该把key这个参数传递过去,即形式如:
a.php?key=$key&page=2 这样的格式
最后一点:$key = $_POST["key"]; 要改成$key = ($_POST["key"]=='')? $_GET["key"]:$_POST["key"];
最后用下面这个放在你的input里
"/>
还是input标签这里报错了~
<html> <head> <meta charset="UTF-8"></head> <script type="text/javascript" src="http://localhost/jquery.js" ></script><script type="text/javascript" > function aurl(i){ var url = window.location.href; if(url.indexOf('?')>0){ url=url.substring(0,url.indexOf('?')) ;} url=url+"?page="+i; document.getElementById("documentForm").action=url; document.getElementById("insu").click(); }</script><body > <form id="documentForm" method="POST"> <p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" value="<?php echo $key ?>"/> </p> <p> <input type="submit" name="submit" id="insu" value="搜索!"/> </p> </form> <?php//$key = $_POST["key"]; $key = ($_POST["key"]=='')? $_GET["key"]:$_POST["key"];if($key==""){ echo "请输入搜索条件"; return;}else{ $_SESSION['key'] = $key;//这里把KEY保存到session}//取得页码$page = @$_GET['page'];//定义每页显示信息条数$page_size = 10;//当页码参数为空时,将页码设为1if ($page == ""){ $page = 1;}$wsdl="http://pica.chalwin.com/service/JsAccessWebService.asmx?wsdl";$client = new SoapClient($wsdl);$param = array('NodeId'=>'1','key'=>$key,'pageIndex'=>$page,'pageSize'=>$page_size);//传参$ret = $client->NewsSearch($param);//执行获取新闻的方法//print_r ($ret);if(isset($ret)&&$ret){ foreach($ret->NewsSearchResult->InheritanceNews as $item) { echo "\n<table border=1 cellspacing='0' width='30%'>\n<tr>"; echo "<td>$item->Title</td>\n"; echo "</tr>"; echo "</table>"; }} else { echo 'no user'; } //总页数 $totalPage = ceil(($item->NewsCount)/$page_size); //上一页链接 $Prev = $page - 1; if ($Prev < 1) { $Prev = 1; } //下一页链接 $Next = $page + 1; if ($Next > $totalPage) { $Next = $totalPage; } //输出上一页链接 if ($page <> 1) { echo '<span><a href="javascript:aurl(1)">First </a></span>'; echo '<span><a href="javascript:aurl(' . $Prev . ')">Prev</a></span>'; } else { echo '<span>First</span>'; echo '<span>Prev</span>'; } //页码数字链接 //显示的数字个数 $pageNumber = 5; //页码数算法 $pagebegin = $page - $pageNumber; if ($page == 1) { $pageend = $pageNumber; } else { $pageend = $page + $pageNumber; } if ($pagebegin <= 0) { $pagebegin = 1; } if ($pageend > $totalPage) { $pageend = $totalPage; } //一次向前翻$pageNumber行 if ($page > $pageNumber) { echo '<span><a href="javascript:aurl('. ($page - $pageNumber) . ')"><<</a></span>'; } //输出动态生成的页码链接 for ($i = $pagebegin; $i <= $pageend; $i++) { if ($i == $page) { echo '<span style="background:#FFCC99">' . $i . '</span>'; } else { echo '<span><a href="javascript:aurl('. $i . ')">' . $i . '</a></span>'; } } //一次向后翻$pageNumber行 if (($totalPage - $page) > 5) { echo '<span><a href="javascript:aurl('. ($page + $pageNumber) . ')">>></a></span>'; } //输出下一页链接 if ($page <> $totalPage) { echo '<span><a href="javascript:aurl('. $Next .')">Next</a></span>'; echo '<span><a href="javascript:aurl('. $totalPage .')">Last</a></span>'; } else { echo '<span>Next</span>'; echo '<span>Last</span>'; } ?></body> </html>
<html> <head> <meta charset="UTF-8"></head> <script type="text/javascript" src="http://localhost/jquery.js" ></script><script type="text/javascript" > function aurl(i){ var url = window.location.href; if(url.indexOf('?')>0){ url=url.substring(0,url.indexOf('?')) ;} url=url+"?page="+i; document.getElementById("documentForm").action=url; document.getElementById("insu").click(); }</script><body > <form id="documentForm" method="POST"> <p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" value="<?php echo $key ?>"/> </p> <p> <input type="submit" name="submit" id="insu" value="搜索!"/> </p> </form> <?php//$key = $_POST["key"]; $key = ($_POST["key"]=='')? $_GET["key"]:$_POST["key"];if($key==""){ echo "请输入搜索条件"; return;}else{ $_SESSION['key'] = $key;//这里把KEY保存到session}//取得页码$page = @$_GET['page'];//定义每页显示信息条数$page_size = 10;//当页码参数为空时,将页码设为1if ($page == ""){ $page = 1;}$wsdl="http://pica.chalwin.com/service/JsAccessWebService.asmx?wsdl";$client = new SoapClient($wsdl);$param = array('NodeId'=>'1','key'=>$key,'pageIndex'=>$page,'pageSize'=>$page_size);//传参$ret = $client->NewsSearch($param);//执行获取新闻的方法//print_r ($ret);if(isset($ret)&&$ret){ foreach($ret->NewsSearchResult->InheritanceNews as $item) { echo "\n<table border=1 cellspacing='0' width='30%'>\n<tr>"; echo "<td>$item->Title</td>\n"; echo "</tr>"; echo "</table>"; }} else { echo 'no user'; } //总页数 $totalPage = ceil(($item->NewsCount)/$page_size); //上一页链接 $Prev = $page - 1; if ($Prev < 1) { $Prev = 1; } //下一页链接 $Next = $page + 1; if ($Next > $totalPage) { $Next = $totalPage; } //输出上一页链接 if ($page <> 1) { echo '<span><a href="javascript:aurl(1)">First </a></span>'; echo '<span><a href="javascript:aurl(' . $Prev . ')">Prev</a></span>'; } else { echo '<span>First</span>'; echo '<span>Prev</span>'; } //页码数字链接 //显示的数字个数 $pageNumber = 5; //页码数算法 $pagebegin = $page - $pageNumber; if ($page == 1) { $pageend = $pageNumber; } else { $pageend = $page + $pageNumber; } if ($pagebegin <= 0) { $pagebegin = 1; } if ($pageend > $totalPage) { $pageend = $totalPage; } //一次向前翻$pageNumber行 if ($page > $pageNumber) { echo '<span><a href="javascript:aurl('. ($page - $pageNumber) . ')"><<</a></span>'; } //输出动态生成的页码链接 for ($i = $pagebegin; $i <= $pageend; $i++) { if ($i == $page) { echo '<span style="background:#FFCC99">' . $i . '</span>'; } else { echo '<span><a href="javascript:aurl('. $i . ')">' . $i . '</a></span>'; } } //一次向后翻$pageNumber行 if (($totalPage - $page) > 5) { echo '<span><a href="javascript:aurl('. ($page + $pageNumber) . ')">>></a></span>'; } //输出下一页链接 if ($page <> $totalPage) { echo '<span><a href="javascript:aurl('. $Next .')">Next</a></span>'; echo '<span><a href="javascript:aurl('. $totalPage .')">Last</a></span>'; } else { echo '<span>Next</span>'; echo '<span>Last</span>'; } ?></body> </html>
<html> <head> <meta charset="UTF-8"></head> <script type="text/javascript" src="http://localhost/jquery.js" ></script><script type="text/javascript" > function aurl(i){ var url = window.location.href; if(url.indexOf('?')>0){ url=url.substring(0,url.indexOf('?')) ;} url=url+"?page="+i; document.getElementById("documentForm").action=url; document.getElementById("insu").click(); }</script><body > <form id="documentForm" method="POST"> <p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" value="<?php echo $key ?>"/> </p> <p> <input type="submit" name="submit" id="insu" value="搜索!"/> </p> </form> <?php//$key = $_POST["key"]; $key = ($_POST["key"]=='')? $_GET["key"]:$_POST["key"];if($key==""){ echo "请输入搜索条件"; return;}else{ $_SESSION['key'] = $key;//这里把KEY保存到session}//取得页码$page = @$_GET['page'];//定义每页显示信息条数$page_size = 10;//当页码参数为空时,将页码设为1if ($page == ""){ $page = 1;}$wsdl="http://pica.chalwin.com/service/JsAccessWebService.asmx?wsdl";$client = new SoapClient($wsdl);$param = array('NodeId'=>'1','key'=>$key,'pageIndex'=>$page,'pageSize'=>$page_size);//传参$ret = $client->NewsSearch($param);//执行获取新闻的方法//print_r ($ret);if(isset($ret)&&$ret){ foreach($ret->NewsSearchResult->InheritanceNews as $item) { echo "\n<table border=1 cellspacing='0' width='30%'>\n<tr>"; echo "<td>$item->Title</td>\n"; echo "</tr>"; echo "</table>"; }} else { echo 'no user'; } //总页数 $totalPage = ceil(($item->NewsCount)/$page_size); //上一页链接 $Prev = $page - 1; if ($Prev < 1) { $Prev = 1; } //下一页链接 $Next = $page + 1; if ($Next > $totalPage) { $Next = $totalPage; } //输出上一页链接 if ($page <> 1) { echo '<span><a href="javascript:aurl(1)">First </a></span>'; echo '<span><a href="javascript:aurl(' . $Prev . ')">Prev</a></span>'; } else { echo '<span>First</span>'; echo '<span>Prev</span>'; } //页码数字链接 //显示的数字个数 $pageNumber = 5; //页码数算法 $pagebegin = $page - $pageNumber; if ($page == 1) { $pageend = $pageNumber; } else { $pageend = $page + $pageNumber; } if ($pagebegin <= 0) { $pagebegin = 1; } if ($pageend > $totalPage) { $pageend = $totalPage; } //一次向前翻$pageNumber行 if ($page > $pageNumber) { echo '<span><a href="javascript:aurl('. ($page - $pageNumber) . ')"><<</a></span>'; } //输出动态生成的页码链接 for ($i = $pagebegin; $i <= $pageend; $i++) { if ($i == $page) { echo '<span style="background:#FFCC99">' . $i . '</span>'; } else { echo '<span><a href="javascript:aurl('. $i . ')">' . $i . '</a></span>'; } } //一次向后翻$pageNumber行 if (($totalPage - $page) > 5) { echo '<span><a href="javascript:aurl('. ($page + $pageNumber) . ')">>></a></span>'; } //输出下一页链接 if ($page <> $totalPage) { echo '<span><a href="javascript:aurl('. $Next .')">Next</a></span>'; echo '<span><a href="javascript:aurl('. $totalPage .')">Last</a></span>'; } else { echo '<span>Next</span>'; echo '<span>Last</span>'; } ?></body> </html>
<html> <head> <meta charset="UTF-8"></head> <script type="text/javascript" src="http://localhost/jquery.js" ></script><script type="text/javascript" > function aurl(i){ var url = window.location.href; if(url.indexOf('?')>0){ url=url.substring(0,url.indexOf('?')) ;} url=url+"?page="+i; document.getElementById("documentForm").action=url; document.getElementById("insu").click(); }</script><body > <form id="documentForm" method="POST"> <p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" value="<?php echo $key ?>"/> </p> <p> <input type="submit" name="submit" id="insu" value="搜索!"/> </p> </form> <?php//$key = $_POST["key"]; $key = ($_POST["key"]=='')? $_GET["key"]:$_POST["key"];if($key==""){ echo "请输入搜索条件"; return;}else{ $_SESSION['key'] = $key;//这里把KEY保存到session}//取得页码$page = @$_GET['page'];//定义每页显示信息条数$page_size = 10;//当页码参数为空时,将页码设为1if ($page == ""){ $page = 1;}$wsdl="http://pica.chalwin.com/service/JsAccessWebService.asmx?wsdl";$client = new SoapClient($wsdl);$param = array('NodeId'=>'1','key'=>$key,'pageIndex'=>$page,'pageSize'=>$page_size);//传参$ret = $client->NewsSearch($param);//执行获取新闻的方法//print_r ($ret);if(isset($ret)&&$ret){ foreach($ret->NewsSearchResult->InheritanceNews as $item) { echo "\n<table border=1 cellspacing='0' width='30%'>\n<tr>"; echo "<td>$item->Title</td>\n"; echo "</tr>"; echo "</table>"; }} else { echo 'no user'; } //总页数 $totalPage = ceil(($item->NewsCount)/$page_size); //上一页链接 $Prev = $page - 1; if ($Prev < 1) { $Prev = 1; } //下一页链接 $Next = $page + 1; if ($Next > $totalPage) { $Next = $totalPage; } //输出上一页链接 if ($page <> 1) { echo '<span><a href="javascript:aurl(1)">First </a></span>'; echo '<span><a href="javascript:aurl(' . $Prev . ')">Prev</a></span>'; } else { echo '<span>First</span>'; echo '<span>Prev</span>'; } //页码数字链接 //显示的数字个数 $pageNumber = 5; //页码数算法 $pagebegin = $page - $pageNumber; if ($page == 1) { $pageend = $pageNumber; } else { $pageend = $page + $pageNumber; } if ($pagebegin <= 0) { $pagebegin = 1; } if ($pageend > $totalPage) { $pageend = $totalPage; } //一次向前翻$pageNumber行 if ($page > $pageNumber) { echo '<span><a href="javascript:aurl('. ($page - $pageNumber) . ')"><<</a></span>'; } //输出动态生成的页码链接 for ($i = $pagebegin; $i <= $pageend; $i++) { if ($i == $page) { echo '<span style="background:#FFCC99">' . $i . '</span>'; } else { echo '<span><a href="javascript:aurl('. $i . ')">' . $i . '</a></span>'; } } //一次向后翻$pageNumber行 if (($totalPage - $page) > 5) { echo '<span><a href="javascript:aurl('. ($page + $pageNumber) . ')">>></a></span>'; } //输出下一页链接 if ($page <> $totalPage) { echo '<span><a href="javascript:aurl('. $Next .')">Next</a></span>'; echo '<span><a href="javascript:aurl('. $totalPage .')">Last</a></span>'; } else { echo '<span>Next</span>'; echo '<span>Last</span>'; } ?></body> </html>
<?phpsession_start();$_SESSION['key'] = $_POST["key"] ;?><html> <head> <meta charset="UTF-8"></head> <script type="text/javascript" src="http://localhost/jquery.js" ></script><script type="text/javascript" > function aurl(i){ var url = window.location.href; if(url.indexOf('?')>0){ url=url.substring(0,url.indexOf('?')) ;} url=url+"?page="+i; document.getElementById("documentForm").action=url; document.getElementById("insu").click(); }</script><body > <form id="documentForm" method="POST" > <p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" value="<?=$_SESSION['key'] ?>"/> </p> <p> <input type="submit" name="submit" id="insu" value="搜索!"/> </p> </form> <?php$key = $_POST["key"]; if($key==""){ echo "请输入搜索条件"; return; }else{ unset($_SESSION['key']);}//取得页码$page = @$_GET['page'];//定义每页显示信息条数$page_size = 10;//当页码参数为空时,将页码设为1if ($page == ""){ $page = 1;}$wsdl="http://pica.chalwin.com/service/JsAccessWebService.asmx?wsdl";$client = new SoapClient($wsdl);$param = array('NodeId'=>'1','key'=>$key,'pageIndex'=>$page,'pageSize'=>$page_size);//传参$ret = $client->NewsSearch($param);//执行获取新闻的方法//print_r ($ret);if(isset($ret)&&$ret){ foreach($ret->NewsSearchResult->InheritanceNews as $item) { echo "\n<table border=1 cellspacing='0' width='30%'>\n<tr>"; echo "<td>$item->Title</td>\n"; echo "</tr>"."</table>"; }} else { echo 'no user'; } //总页数 $totalPage = ceil(($item->NewsCount)/$page_size); //上一页链接 $Prev = $page - 1; if ($Prev < 1) { $Prev = 1; } //下一页链接 $Next = $page + 1; if ($Next > $totalPage) { $Next = $totalPage; } //输出上一页链接 if ($page <> 1) { echo '<span><a href="javascript:aurl(1)">First </a></span>'; echo '<span><a href="javascript:aurl(' . $Prev . ')">Prev</a></span>'; } else { echo '<span>First</span>'; echo '<span>Prev</span>'; } //页码数字链接 //显示的数字个数 $pageNumber = 5; //页码数算法 $pagebegin = $page - $pageNumber; if ($page == 1) { $pageend = $pageNumber; } else { $pageend = $page + $pageNumber; } if ($pagebegin <= 0) { $pagebegin = 1; } if ($pageend > $totalPage) { $pageend = $totalPage; } //一次向前翻$pageNumber行 if ($page > $pageNumber) { echo '<span><a href="javascript:aurl('. ($page - $pageNumber) . ')"><<</a></span>'; } //输出动态生成的页码链接 for ($i = $pagebegin; $i <= $pageend; $i++) { if ($i == $page) { echo '<span style="background:#FFCC99">' . $i . '</span>'; } else { echo '<span><a href="javascript:aurl('. $i . ')">' . $i . '</a></span>'; } } //一次向后翻$pageNumber行 if (($totalPage - $page) > 5) { echo '<span><a href="javascript:aurl('. ($page + $pageNumber) . ')">>></a></span>'; } //输出下一页链接 if ($page <> $totalPage) { echo '<span><a href="javascript:aurl('. $Next .')">Next</a></span>'; echo '<span><a href="javascript:aurl('. $totalPage .')">Last</a></span>'; } else { echo '<span>Next</span>'; echo '<span>Last</span>'; } ?></body> </html>
<?phpsession_start();$_SESSION['key'] = $_POST["key"] ;?><html> <head> <meta charset="UTF-8"></head> <script type="text/javascript" src="http://localhost/jquery.js" ></script><script type="text/javascript" > function aurl(i){ var url = window.location.href; if(url.indexOf('?')>0){ url=url.substring(0,url.indexOf('?')) ;} url=url+"?page="+i; document.getElementById("documentForm").action=url; document.getElementById("insu").click(); }</script><body > <form id="documentForm" method="POST" > <p> 输入关键字:<br/> <input type="text" name="key" size="6" maxlength="6" value="<?=$_SESSION['key'] ?>"/> </p> <p> <input type="submit" name="submit" id="insu" value="搜索!"/> </p> </form> <?php$key = $_POST["key"]; if($key==""){ echo "请输入搜索条件"; return; }else{ unset($_SESSION['key']);}//取得页码$page = @$_GET['page'];//定义每页显示信息条数$page_size = 10;//当页码参数为空时,将页码设为1if ($page == ""){ $page = 1;}$wsdl="http://pica.chalwin.com/service/JsAccessWebService.asmx?wsdl";$client = new SoapClient($wsdl);$param = array('NodeId'=>'1','key'=>$key,'pageIndex'=>$page,'pageSize'=>$page_size);//传参$ret = $client->NewsSearch($param);//执行获取新闻的方法//print_r ($ret);if(isset($ret)&&$ret){ foreach($ret->NewsSearchResult->InheritanceNews as $item) { echo "\n<table border=1 cellspacing='0' width='30%'>\n<tr>"; echo "<td>$item->Title</td>\n"; echo "</tr>"."</table>"; }} else { echo 'no user'; } //总页数 $totalPage = ceil(($item->NewsCount)/$page_size); //上一页链接 $Prev = $page - 1; if ($Prev < 1) { $Prev = 1; } //下一页链接 $Next = $page + 1; if ($Next > $totalPage) { $Next = $totalPage; } //输出上一页链接 if ($page <> 1) { echo '<span><a href="javascript:aurl(1)">First </a></span>'; echo '<span><a href="javascript:aurl(' . $Prev . ')">Prev</a></span>'; } else { echo '<span>First</span>'; echo '<span>Prev</span>'; } //页码数字链接 //显示的数字个数 $pageNumber = 5; //页码数算法 $pagebegin = $page - $pageNumber; if ($page == 1) { $pageend = $pageNumber; } else { $pageend = $page + $pageNumber; } if ($pagebegin <= 0) { $pagebegin = 1; } if ($pageend > $totalPage) { $pageend = $totalPage; } //一次向前翻$pageNumber行 if ($page > $pageNumber) { echo '<span><a href="javascript:aurl('. ($page - $pageNumber) . ')"><<</a></span>'; } //输出动态生成的页码链接 for ($i = $pagebegin; $i <= $pageend; $i++) { if ($i == $page) { echo '<span style="background:#FFCC99">' . $i . '</span>'; } else { echo '<span><a href="javascript:aurl('. $i . ')">' . $i . '</a></span>'; } } //一次向后翻$pageNumber行 if (($totalPage - $page) > 5) { echo '<span><a href="javascript:aurl('. ($page + $pageNumber) . ')">>></a></span>'; } //输出下一页链接 if ($page <> $totalPage) { echo '<span><a href="javascript:aurl('. $Next .')">Next</a></span>'; echo '<span><a href="javascript:aurl('. $totalPage .')">Last</a></span>'; } else { echo '<span>Next</span>'; echo '<span>Last</span>'; } ?></body> </html>
你搜索‘田径运动会’,看是不是还出那个错误。如果出,就用我下面的代码
在foreach加了个if语句来判断结果。
<?phpsession_start ();$_SESSION['key'] = $_POST["key"] ;?> <meta> <script></script><script> function aurl(i){ var url = window.location.href; if(url.indexOf('?')>0){ url=url.substring(0,url.indexOf('?')) ;} url=url+"?page="+i; document.getElementById("documentForm").action=url; document.getElementById("insu").click(); }</script>'1','key'=>$key,'pageIndex'=>$page,'pageSize'=>$page_size);//传参$ret = $client->NewsSearch($param);//执行获取新闻的方法//print_r ($ret);if(isset($ret)&&$ret){ if (is_array($ret->NewsSearchResult->InheritanceNews)) { foreach($ret->NewsSearchResult->InheritanceNews as $item) { echo "\n
$item->Title | \n"; echo "
$ret->NewsSearchResult->InheritanceNews->title | \n"; echo "