English 中文(简体)
使用 Get 访问我的Sql 查询中的 PHP Zend_ Puidea
原标题:PHP Zend_Paginator on mySql query using GET

我试图用 调用基于 Get 搜索字符串加载的查询页面。 查询基本上做以下工作: :

SELECT * FROM table WHERE column LIKE  %searchstring%  OR alt_column LIKE  %searchstring% ;

当通过搜索/ 提交文本窗体调用查询时,查询工作正常, URL 返回类似

URLINK.php?search=searchstring

然而,当试图移动到下一页时,程序会把我丢回外形的替代 URL( 用于错误或没有页面显示) -- 希望最后一行能说得通, 现在已经很晚了, 并且正在尽我最大的努力, 以透明的方式输入它 。

在对 URL.php? search=searstring 使用方格的最佳方法是什么?

更多点在呼唤到url

//search query 
$search = searchQuery( search ,  list_sql_rows.php );
$results - searchTable($dbRead, $search);

使用以上变量的搜索方法,按以下顺序排列

if(isset($_POST[ submit_search ])) { $searchstring = $_POST[ searchstring ];
if($searchstring) { header( Location: results.php?search=  . $searchstring); } }

此位工作良好, 但当我试图用 paginator 调用 results.php? page=2 时, 系统会将我恢复到上述的 URL list_ sql_rows.php 。 任何想法/ 评论都会受到赞赏 。

只需从搜索.php页面中澄清搜索字段/ form 即可将 < code> $searstring 发送到结果.php页面 $_POST & amp; $_GET 以安全性失效。 获取方法会在 URL 标题中发送 < code>$searstring < / code> 的搜索字段/ fpp? search=$searststring 以安全性发送搜索字段/ 。 这效果很好。 渐渐渐渐渐渐渐渐渐变回回回 URL URL < pengleem > resulges.phpp=2 , 因此似乎 < codef > < $_ GET < /code > 可能不会成为选择的方法。

UPDATE On the write track now paginate works it is my link structure that is broken. _results_samples.php?search=robert&page=4_ will in fact return page 4 of the paginated results using the word ROBERT

SOLUTION FOUND VIA variant suggestion by ROCKYFORD variant of recommended method by first persisting $searchstring change to paginate links as shown below

<a href= " . $_SERVER[ PHP_SELF ] . "?search=" . $searchstring . "&page={$page} >$page</a>
最佳回答

您需要确保您保存请求之间的查询字符串, 使用 Zend_ Say_ Namespace 或 Zend_ registry 。

Zend_ Padinator 每次在使用 DbTableSect 或 DbSect 调整器时每次使用 DbTableSect 或 DbSect 调整器以查询按下 db 时加载一页, 它只会更改限制选项 。

或者将整个查询结果丢入 Zend_Paginator_Adapter_Aray 中,然后通过数组页面。

[edit]
you are going to have to persist the query string between requests someway so you can put it back in the url string, I usually use Zend_Registry, but then I use the whole MVC stack. You don t seem to be using the whole stack so you ll need another method, probably $_SESSION would work. I m sure there are many other ways to persist this data.

P.S.你没有提到你正在使用哪个适配器,所以我做了一些假设。

[edit] Personally I always use $_post for this when possible to avoid all this, only seem to have this problem with $_get.

问题回答

Here is the example of correct using of pagination: in action-method:

$select = $clients->getAll();                               
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
$paginator->setCurrentPageNumber($this->_getParam( page ));
$paginator->setItemCountPerPage(20);
$this->view->clients = $paginator;

在视图脚本中 :

<?php if (count($this->clients) > 0): ?>
...
    <?php echo $this->paginationControl($this->clients,  Sliding ,  partials/paginator.phtml ); ?>
<?php else: ?>
        <h3 class="notice">No registered clients found!</h3>
<?php endif; ?>

但即使你无法完成这个变体, 你也可以尝试组成自己的部件, Zend 只会帮助我们完成一些任务。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签