将变量保持在分页中 [英] keep variables in pagination

查看:74
本文介绍了将变量保持在分页中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图为我在网站上运行的搜索设置分页,我会

尝试解释我能做的最简单:


当我点击search.php上的搜索按钮时,收到的数据和

存储在results.php中的变量中,MySQL结构似乎正常工作

如预期,虽然我遇到了一些问题:


一旦我点击第2页链接,我什么也没得到,既没有结果

也没有页码。


我知道为什么会发生这种情况:点击任何Page X后链接,页面

自我重新加载,这改变了VARIABLES中的存储值(i
假定为0或没有),因此,MySQL结构不起作用,因为

没有正确的数据来设置查询。


说明显而易见的,如果我设置固定值而不是变量my

结构完美有效:


- >结果显示

- >页码反映了MySQL中存储的数据

- >页码是完全有用的,我可以用任何方式点击它们

,它总是有效。


但由于数据定义,我无法设置固定值在search.php中,所以

results.php不能有固定值,否则,搜索不是一个

搜索,它只是一个固定的d


所以我的问题是如何在每次自动重新加载页面后保持从search.php

收到的值。

这是我正在使用的代码:


<?php


//数据库连接

包含''db.php'';


//这是保持每页重新连接的变量


$ table = $ _POST [''table''];

$ data02 = $ _POST [''data02''];

$ data03 = $ _POST [''data03'' ];

$ data04 = $ _POST [''data04''];

$ data05 = $ _POST [''data05''];

$ data06 = $ _POST [''data06''];

$ data07 = $ _POST [ 'data07''];

$ data08 = $ _POST [''data08''];

$ data09 = $ _POST [''data09''];


//如果是当前页码,如果没有,请使用它,设置一个!


if(!isset($ _ GET [''page'' ])){

$ page = 1;

} else {

$ page = $ _GET [''page'']; < br $>
}


//定义每页的结果数

$ max_results = 10;


//根据当前页码确定查询限制。


$ from =(($ page * $ max_results) - $ max_results );


//仅对当前页码的结果执行MySQL查询


//这个变量数据(上面已宣布)页面重新删除后被删除

//这就是我想要保留每个重载的数据。


$ sql = mysql_query(" SELECT * FROM` $ table` WHERE`data02` LIKE

''%$ data02%''和`data03` LIKE''%$ data03%' AND`data04` LIKE''%$ data04%''

AND`data05` LIKE''%$ data05%''和'data06` LIKE''%$ data06%''和

`data07`> = $ data08 AND`data07`< = $ data09 ORDER BY`data07`ASC LIMIT

$ from,$ max_results");


echo''< table id =" cssstyle">''。" \ n" ;;

echo"< tr> <的第i;顶部和LT; /第> <的第i;顶部和LT; /第> <的第i;顶部和LT; /第> < th> Top< / th>

< th> Top< / th> <的第i;顶部和LT; /第> <的第i;顶部和LT; /第> < th> Top< / th>

< th> Top< / th>"。" \ n"。"< / tr>"。" \ n" ;;


while($ row = mysql_fetch_array($ sql)){//构建你的格式化

以下。


echo''< tr>''。" \ n"。"< td align =''left''>"。" \ n";

echo $ row [''1strow''];

echo" \ n"。"< / td>"。" \ n"。"< ; td align =''center''>"。" \ n" ;;

echo $ row [''2ndrow''];

echo" ; \ n"。"< / td>"。" \ n"。"< td align =''center''>"。" \ n" ;;

echo $ row [''3rdrow''];

echo" \ n"。"< / td>"。" \ n"。" ;< td align =''center''>"。" \ n" ;;

echo $ row [''4throw''];

回音" \ n"。"< / td>"。" \ n"。"< td align =''center''>"。" \\\
";

echo $ row [''5throw''];

echo" \ n"。"< / td>"。" \ n"。 "< td align =''center''>"。" \ n";

echo $ row [''6throw''];

echo" \ n"。"< / td>"。" \ n"。"< td align =''center''>"。" \ n" ;;

echo $ row [''7throw''];

echo" \ n"。"< / td>"。" \ n" ;"< td width =''28%''align =''left''>"。" \ n" ;;

echo $ row [''8throw' '];

echo" \ n"。"< / td>"。" \ n"。"< td align =''center''> "。" \ n" ;;

echo $ row [''9throw''];

echo"< / a>"。&q UOT; \\\
"。"< / TD>"。" \\\
"。"< / TR>"。" \\\
"。" \\\
英寸; <无线电通信/>
}

echo"< / table>"。" \ n"。"< / div>"。" \ n"。 "<! - Results-wrapper Ends

- >"。" \ n";


//找出DB中的结果总数:


//" $ table"页面重新启动后价值不会保留。

//和其他价值观一样,它应该是KEPT。


$ total_results = mysql_result(mysql_query(" SELECT COUNT(*)as Num FROM

$ table"),0);


//计算总页数。总是围绕使用ceil()

$ total_pages = ceil($ total_results / $ max_results);


//构建页码超链接

echo"< div id =''pages''>< center>选择一个页面< br />" ;;


//构建上一个链接

if($ page> 1){

$ prev =($ page - 1);

echo"< a

href = \""。$ _ SERVER [''PHP_SELF'']。"?page = $ prev\">& lt;& lt; Previous< /一个> " ;;

}


for($ i = 1; $ i< = $ total_pages; $ i ++){

if(($ page)== $ i){

echo" $ i";

} else {

echo" ;< a href = \""。$ _ SERVER [''PHP_SELF'']。"?page = $ i \"> $ i< / a> ;

}

}


//构建下一个链接

if($ page < $ total_pages){

$ next =($ page + 1);

echo"< a

href = \ "。$ _ SERVER [''PHP_SELF'']。"?page = $ next \"> Next& gt;& gt;< / a>" ;;

}

echo"< / center>"。" \ n";


?>


我希望你能帮助我,我不是掌握php,但我理解了很多

它;我实际上认为可以解决我的问题的方法将来自: http://www.mysite.com/results.php?pa...03=XX&var04= XX


但那正是我不知道该怎么办U_U


谢谢,我希望你能帮助我


问候,

EOZyo。

Hi, i''m trying to set pagination for a search i run on my website, i''ll
try to explain the easiest i can:

When i click the search button on search.php, data is received and
stored in variables within results.php, MySQL structure seems to work
as expected, although i get some problems:

As soon as i click on the "Page 2" Link, i get nothing, neither results
nor page numbers.

I know why this happens: after clicking on any "Page X" link, the page
self-reloads and this changes the stored value in the VARIABLES (i
assume to 0 or nothing), therefore, MySQL structure doesn''t work, since
there''s no correct data to set the query.

Stating the obvious, if i set a fixed value instead of a variable my
structure perfectly works:

-> Results are displayed
-> Page numbers reflect the data stored in MySQL
-> Page numbers are fully fonctional, i can click them
in any way, and it always work.

But i cannot set a fixed value since data is defined in search.php, so
results.php cannot have a fixed values, otherwise, the search is not a
search, it''s only a fixed d

So my question is how do i keep the values received from the search.php
after every self-reload of the page.

This is the code i am using:

<?php

// Database Connection
include ''db.php'';

// THIS ARE THE VARIABLES TO KEEP EVERY PAGE RELOAD

$table = $_POST[''table''];
$data02 = $_POST[''data02''];
$data03 = $_POST[''data03''];
$data04 = $_POST[''data04''];
$data05 = $_POST[''data05''];
$data06 = $_POST[''data06''];
$data07 = $_POST[''data07''];
$data08 = $_POST[''data08''];
$data09 = $_POST[''data09''];

// If current page number, use it if not, set one!

if(!isset($_GET[''page''])){
$page = 1;
} else {
$page = $_GET[''page''];
}

// Define the number of results per page

$max_results = 10;

// Figure out the limit for the query based on the current page number.

$from = (($page * $max_results) - $max_results);

// Perform MySQL query on only the current page number''s results

// THIS VARIABLES DATA (DECLARED ABOVE) IS ERASED AFTER THE PAGE RELOAD
// THIS IS THE DATA I''D LIKE TO KEEP FOR EVERY RELOAD.

$sql = mysql_query("SELECT * FROM `$table` WHERE `data02` LIKE
''%$data02%'' AND `data03` LIKE ''%$data03%'' AND `data04` LIKE ''%$data04%''
AND `data05` LIKE ''%$data05%'' AND `data06` LIKE ''%$data06%'' AND
`data07` >= $data08 AND `data07` <= $data09 ORDER BY `data07` ASC LIMIT
$from, $max_results");

echo ''<table id="cssstyle">''."\n";
echo "<tr> <th>Top</th> <th>Top</th> <th>Top</th> <th>Top</th>
<th>Top</th> <th>Top</th> <th>Top</th> <th>Top</th>
<th>Top</th>"."\n"."</tr>"."\n";

while($row = mysql_fetch_array($sql)){ // Build your formatted
below.

echo ''<tr>''."\n"."<td align=''left''>"."\n";
echo $row[''1strow''];
echo "\n"."</td>"."\n"."<td align=''center''>"."\n";
echo $row[''2ndrow''];
echo "\n"."</td>"."\n"."<td align=''center''>"."\n";
echo $row[''3rdrow''];
echo "\n"."</td>"."\n"."<td align=''center''>"."\n";
echo $row[''4throw''];
echo "\n"."</td>"."\n"."<td align=''center''>"."\n";
echo $row[''5throw''];
echo "\n"."</td>"."\n"."<td align=''center''>"."\n";
echo $row[''6throw''];
echo "\n"."</td>"."\n"."<td align=''center''>"."\n";
echo $row[''7throw''];
echo "\n"."</td>"."\n"."<td width=''28%'' align=''left''>"."\n";
echo $row[''8throw''];
echo "\n"."</td>"."\n"."<td align=''center''>"."\n";
echo $row[''9throw''];
echo "</a>"."\n"."</td>"."\n"."</tr>"."\n"."\n";
}
echo "</table>"."\n"."</div>"."\n"."<!-- Results-wrapper Ends
-->"."\n";

// Figure out the total number of results in DB:

// "$table" VALUE IS NOT KEEPT AFTER PAGE RELOADS.
// AND LIKE THE OTHER VALUES, IT SHOULD BE KEPT.

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM
$table"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Build Page Number Hyperlinks
echo "<div id=''pages''><center>Select a Page<br />";

// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a
href=\"".$_SERVER[''PHP_SELF'']."?page=$prev\">&lt;&lt;Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER[''PHP_SELF'']."?page=$i\">$i</a> ";
}
}

// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a
href=\"".$_SERVER[''PHP_SELF'']."?page=$next\">Next&gt;&gt;</a>";
}
echo "</center>"."\n";

?>

I hope you can help me, i''m don''t master php, but i understand a lot of
it; I''m actually thinking that what might solve my problem will come
from something like:
http://www.mysite.com/results.php?pa...03=XX&var04=XX

But that''s exactly what i don''t know how to do U_U

Thanks, and i hope you could help me

Regards,
EOZyo.

推荐答案

table =


_POST [''table''];
_POST[''table''];


data02 =


这篇关于将变量保持在分页中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆