|
Posted by d on 11/17/98 11:39
"EOZyo" <eozyo6@gmail.com> wrote in message
news:1139444977.027689.301400@z14g2000cwz.googlegroups.com...
> 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\"><<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>></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?page=XX&var02=XX&var03=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.
Take a look at using sessions:
http://www.php.net/sessions
They allow you to store a value in one script, and then access it in later
scripts. They're very easy to use, and might be what you need.
dave
Navigation:
[Reply to this message]
|