On Monday 28 January 2002 18:42, Jason Wong wrote:

> > $page behaves just fine :

> > page: 2 <- yup, it's incrementing, all right...
> > nr_pages: 230

> > Whack! Doesn't work any more...  It's starting to drive me mad.

> Me too. Post the full code so we can all revel in this madness!

All rightey. Here it goes in it's (almost) full glory!

// The nav-function that's responsible for updateing the query

if($nav) {

        if($go=="next") {
                if($page < $nr_pages && $page >= 0) {
                         $page++;
                         $milla= (($page) * 20).",";    // replace with
                         echo "millä: " . $milla;               // echo out debug info
                         $mita = (($page-1) * 20).",";  // replace what
                         echo "mitä: " .$mita;          // echo out more debug info
                         $query=ereg_replace($mita,$milla,$query); 
                }
        }
        if($go=="prev") {
                if($page>=1 && $page <= $nr_pages) {
                        $page--;
                        $milla = (($page) * 20).",";
                        echo "millä: " . $milla;
                        $mita  = (($page+1) * 20).",";
                        echo "mitä: " . $mita;
                        $query=ereg_replace($mita,$milla,$query);
                }
        }

        echo "query from nav(): " .$query;
        $result=mysql_query($query,$database)
        or die("BEATCH,WHINE AND MOAN!");  // hehe. just a debug output.
        print_taulukko();
        
}


function print_taulukko() {

        ?>
        <FORM ACTION="page.php" METHOD="POST">
        <?              
        //debug
        echo "query: " . $query;
        echo "<BR><BR>";
        echo "page: " . $page;
        echo "<BR>";
        echo "nr_pages: " .$nr_pages;
        //endof debug

        while($row=mysql_fetch_row($result)) {
                [snip away stuff that doesn't really matter]
        }
        ?>
        <TR>
        <TD COLSPAN="5" WIDTH="50%" ALIGN="CENTER"><INPUT <?php if($page == 0) {echo 
"DISABLED";} ?> TYPE=button 
                VALUE="Edellinen sivu" 
onclick="parent.location='page.php?nav=true&go=prev';"></TD>
        
        <TD COLSPAN="4" WIDTH="50%" ALIGN="CENTER"><INPUT <?php if($page >= 
($nr_pages-1)) { echo "DISABLED"; }?> TYPE=button 
                VALUE="Seuraava sivu" 
onclick="parent.location='page.php?nav=true&go=next';"></TD>
        </TR>
        <?
        }


And that's basically it. There's a function responsible for
reading user input and constructing the sql-query, and it
places the sql in $query, stuffs it down MySQL and throws
it over to print_taulukko(), and it seems to be working right,
since the first result always is the correct one. It also session_registers
$query. (yes, I use session_register("query"), not session_register($query).)

I checked the sess_<whatever> file step by step when testing again just to see
exactly what is put in it, but it seems to be a well-behaved little textfile.

Make any sense out of the code?

Cheers mate, 
Markus

-- 
Markus Lervik
Linux-administrator with a kungfoo grip
Vaasa City Library - Regional Library
[EMAIL PROTECTED]
+358-6-325 3589 / +358-40-832 6709

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to