keep variables in pagination

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • EOZyo

    keep variables in pagination

    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("SE LECT * 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_arr ay($sql)){ // Build your formatted
    below.

    echo '<tr>'."\n"."<t d 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(my sql_query("SELE CT COUNT(*) as Num FROM
    $table"),0);

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

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

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

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

    // Build Next Link
    if($page < $total_pages){
    $next = ($page + 1);
    echo "<a
    href=\"".$_SERV ER['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:




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

    Thanks, and i hope you could help me

    Regards,
    EOZyo.

  • d

    #2
    Re: keep variables in pagination

    "EOZyo" <eozyo6@gmail.c om> wrote in message
    news:1139444977 .027689.301400@ z14g2000cwz.goo glegroups.com.. .[color=blue]
    > 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("SE LECT * 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_arr ay($sql)){ // Build your formatted
    > below.
    >
    > echo '<tr>'."\n"."<t d 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(my sql_query("SELE CT COUNT(*) as Num FROM
    > $table"),0);
    >
    > // Figure out the total number of pages. Always round up using ceil()
    > $total_pages = ceil($total_res ults / $max_results);
    >
    > // Build Page Number Hyperlinks
    > echo "<div id='pages'><cen ter>Select a Page<br />";
    >
    > // Build Previous Link
    > if($page > 1){
    > $prev = ($page - 1);
    > echo "<a
    > href=\"".$_SERV ER['PHP_SELF']."?page=$prev\" >&lt;&lt;Previo us</a> ";
    > }
    >
    > for($i = 1; $i <= $total_pages; $i++){
    > if(($page) == $i){
    > echo "$i ";
    > } else {
    > echo "<a href=\"".$_SERV ER['PHP_SELF']."?page=$i\">$i </a> ";
    > }
    > }
    >
    > // Build Next Link
    > if($page < $total_pages){
    > $next = ($page + 1);
    > echo "<a
    > href=\"".$_SERV ER['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.[/color]

    Take a look at using 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


    Comment

    • adam410@gmail.com

      #3
      Re: keep variables in pagination

      You could pass them in the query string, but that is cumbersome, You
      could also put all the variables in to hidden inputs, then instead of
      making the next page link href directly to the next page have it do a
      javascript form.submit.

      Comment

      • mannerboy

        #4
        Re: keep variables in pagination

        i haven't read through it ,but i wish something below can be helpful!

        if(empty($_SESS ION['search_sql']) && isset($_POST[submit])){
        // to construct search_sql
        $search_sql = ......
        $SESSION[search_sql] = $search_sql;
        }else{
        $search_sql = $_SESSION[search_sql];
        }

        $per_page = 20;
        $start = ($pageno-1)*$per_page;

        $query = mysql_query($se arch_sql." LIMIT ".$start.",".$p er_page,$link);
        ............

        Comment

        • Drakazz

          #5
          Re: keep variables in pagination

          $_POST variables are only posted at one request, they are neither a
          cookie or a session.

          try using sessions :)

          Comment

          • EOZyo

            #6
            Re: keep variables in pagination

            Well, i started working with cookies, what i did to solve the problem
            is the following:

            Data is sent from page.php into search.php which stores the information
            in cookies and this page forwards to results.php

            -> Data from page.php is sent with a search box that uses POST.
            -> Data received from page.php into search.php is taken with
            $_POST['table']
            -> Data in results.php is retreived with $_COOKIE['table']

            Do you think this is fine or should i look for something more direct?
            what i mean is straight from page.php into results.php.

            Everything is working PERFECTLY with this structure, i'm just wondering
            if it's practical or if i'm probably repeating a step that i could
            avoid.

            Thank you all!

            Comment

            • Jim Michaels

              #7
              Re: keep variables in pagination


              "d" <d@example.co m> wrote in message
              news:6%wGf.1731 3$wl.15058@text .news.blueyonde r.co.uk...[color=blue]
              > "EOZyo" <eozyo6@gmail.c om> wrote in message
              > news:1139444977 .027689.301400@ z14g2000cwz.goo glegroups.com.. .[color=green]
              >> 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("SE LECT * 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_arr ay($sql)){ // Build your formatted
              >> below.
              >>
              >> echo '<tr>'."\n"."<t d align='left'>". "\n";
              >> echo $row['1strow'];[/color][/color]
              [color=blue][color=green]
              >> echo "\n"."</td>"."\n"."<td align='center'> "."\n";
              >> echo $row['2ndrow'];[/color][/color]

              why not just simplify this to...
              echo "\n</td>\n<td align='center'> \n$row[2ndrow]";
              that other way looke like the hard way to do things. And if you need double
              quotes in the string, just use \"
              [color=blue][color=green]
              >> 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(my sql_query("SELE CT COUNT(*) as Num FROM
              >> $table"),0);
              >>
              >> // Figure out the total number of pages. Always round up using ceil()
              >> $total_pages = ceil($total_res ults / $max_results);
              >>
              >> // Build Page Number Hyperlinks
              >> echo "<div id='pages'><cen ter>Select a Page<br />";
              >>
              >> // Build Previous Link
              >> if($page > 1){
              >> $prev = ($page - 1);
              >> echo "<a
              >> href=\"".$_SERV ER['PHP_SELF']."?page=$prev\" >&lt;&lt;Previo us</a> ";
              >> }
              >>
              >> for($i = 1; $i <= $total_pages; $i++){
              >> if(($page) == $i){
              >> echo "$i ";
              >> } else {
              >> echo "<a href=\"".$_SERV ER['PHP_SELF']."?page=$i\">$i </a> ";
              >> }
              >> }
              >>
              >> // Build Next Link
              >> if($page < $total_pages){
              >> $next = ($page + 1);
              >> echo "<a
              >> href=\"".$_SERV ER['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.[/color]
              >
              > 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
              >[/color]


              Comment

              • Jim Michaels

                #8
                Re: keep variables in pagination


                "EOZyo" <eozyo6@gmail.c om> wrote in message
                news:1139444977 .027689.301400@ z14g2000cwz.goo glegroups.com.. .[color=blue]
                > 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("SE LECT * 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_arr ay($sql)){ // Build your formatted
                > below.
                >
                > echo '<tr>'."\n"."<t d 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(my sql_query("SELE CT COUNT(*) as Num FROM
                > $table"),0);
                >
                > // Figure out the total number of pages. Always round up using ceil()
                > $total_pages = ceil($total_res ults / $max_results);
                >
                > // Build Page Number Hyperlinks
                > echo "<div id='pages'><cen ter>Select a Page<br />";
                >
                > // Build Previous Link
                > if($page > 1){
                > $prev = ($page - 1);
                > echo "<a
                > href=\"".$_SERV ER['PHP_SELF']."?page=$prev\" >&lt;&lt;Previo us</a> ";
                > }
                >
                > for($i = 1; $i <= $total_pages; $i++){
                > if(($page) == $i){
                > echo "$i ";
                > } else {
                > echo "<a href=\"".$_SERV ER['PHP_SELF']."?page=$i\">$i </a> ";
                > }
                > }
                >
                > // Build Next Link
                > if($page < $total_pages){
                > $next = ($page + 1);
                > echo "<a
                > href=\"".$_SERV ER['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
                >[/color]

                That URL there is what you would use $_GET[] to get your form variables
                with.
                Even if your form method is set for post, you can still use get, but you
                will notice that when people hit the back button on their browser your old
                variables will come back on you, so be picky about when you use the url for.
                Actually, I think it can also repost old form data too, especially if the
                user hits refresh.
                Use $_POST for post form vars of course.
                You also have the option of using $_SESSION[]
                http://us3.php.net/manual/en/function.session-start.php to keep data between
                pages, which is a good way to hide it.
                [color=blue]
                > But that's exactly what i don't know how to do U_U
                >
                > Thanks, and i hope you could help me
                >
                > Regards,
                > EOZyo.
                >[/color]


                Comment

                • EOZyo

                  #9
                  Re: keep variables in pagination

                  > why not just simplify this to...[color=blue]
                  > echo "\n</td>\n<td align='center'> \n$row[2ndrow]";
                  > that other way looke like the hard way to do things. And if you need double
                  > quotes in the string, just use \"[/color]

                  Hi Jim, thanks for the advice, i've have changed everything in my
                  source code so it's more "legible" now :)

                  I'm new with PHP and i've learned everything i know from tutorials on
                  the net, the problem with them is that sometimes, little things (like
                  \', \t, \n \") are overseen and ppl ignore them since they are rookies
                  mistakes, but rookies (like me) well, don't know about them and we,
                  actually, make those mistakes :S

                  Thanks again for the tip :D

                  I have a question though, what's better to use (in a very general way)
                  SESSIONS or COOKIE? I mean i worked already with cookies and everything
                  works but if i need to learn one or the other, what would be the best?

                  Regards,
                  EOZyo

                  Comment

                  • Tim Roberts

                    #10
                    Re: keep variables in pagination

                    "EOZyo" <eozyo6@gmail.c om> wrote:[color=blue]
                    >
                    >I have a question though, what's better to use (in a very general way)
                    >SESSIONS or COOKIE? I mean i worked already with cookies and everything
                    >works but if i need to learn one or the other, what would be the best?[/color]

                    Every time you create a cookie, you are sending more crapola over to the
                    client computer, to be stored on their hard disk, and ALL of your cookies
                    are transmitted back to you with EVERY http request the browser makes.

                    With a session, PHP basically sends one cookie, and then uses that cookie
                    to look up information that is stored locally, on your server. The
                    bandwidth impact is much lower.
                    --
                    - Tim Roberts, timr@probo.com
                    Providenza & Boekelheide, Inc.

                    Comment

                    • EOZyo

                      #11
                      Re: keep variables in pagination

                      Hi Tim, thanks for clarifying, i guess that switching from cookies to
                      sessions isn't a big mess, is it? I mean, I would only have to change
                      the code and settings related to $_COOKIE for $_SESSION??

                      What i meant is like in results.php i have $foo =
                      $_COOKIE['something']; i should change that for $foo =
                      $_SESSION['something']; obviously, setting the session_start and stuff
                      like that in the respective pages (the one the stores the info and the
                      one that retrieves it, am i right?

                      Thanks!
                      EOZyo



                      [color=blue]
                      > Every time you create a cookie, you are sending more crapola over to the
                      > client computer, to be stored on their hard disk, and ALL of your cookies
                      > are transmitted back to you with EVERY http request the browser makes.
                      >
                      > With a session, PHP basically sends one cookie, and then uses that cookie
                      > to look up information that is stored locally, on your server. The
                      > bandwidth impact is much lower.
                      > --
                      > - Tim Roberts, timr@probo.com
                      > Providenza & Boekelheide, Inc.[/color]

                      Comment

                      Working...