#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Sweden
    Posts
    32
    Rep Power
    14
    I found a updated version of Rod Kreisler's sample for next/prev buttons with MySQL results.

    The problem is that I want to use "&" in the URL, like: www.host.com/page.php3?id=users&show=20

    This is the code i'm using...
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    function dauthor()
    {
    include("conf.inc");
    include("mysql.cfg");


    if (empty($offset) &#0124; &#0124; $offset < 0) {
    $offset=0;
    }

    $limit = 20;
    $numresults = mysql_query("SELECT * FROM coder", $con);
    $totalrows = mysql_num_rows($numresults);

    $begin =($offset+1);
    $end = ($begin+($limit-1));
    if ($end > $totalrows) {
    $end = $totalrows;
    }

    echo "There are $totalrows poems in the database<BR>and now showing $begin to $end records.<BR><BR>";

    $query = "SELECT * FROM coder ORDER BY author LIMIT $offset, $limit";
    $result = mysql_query($query, $con);

    while($data = mysql_fetch_array($result)) {

    $author = $data[author];
    $title = $data[title];
    $coder_id = $data[coder_id];
    $user_id = $data[user_id];
    $email = $data[email];
    $poem = $data[poem];
    $nickname = $data[nickname];
    $authorpoem = "$poem";

    if (strlen($title) > 30)
    {
    $title = substr($title, 0, 30) . "&nbsp;...";
    } else { echo "<BR>"; }

    if (strlen($author) > 20)
    {
    $author = substr($author, 0, 20) . "&nbsp;...";
    } else { echo "<BR>"; }

    if (strlen($authorpoem) > 80)
    {
    $authorpoem = substr($authorpoem, 0, 80) . "&nbsp;<a href="$root$display?id=$coder_id"><FONT COLOR=FFFFFF>...</FONT></A><BR>";
    }

    }
    echo "<BR><BR><FONT FACE=Arial SIZE=-2>Navigator :&nbsp;&nbsp;&nbsp;&nbsp;";

    if ($offset!=0) {
    $prevoffset=$offset-$limit;
    echo "<a href="$root$archive?id=author" . rawurldecode (rawurlencode('&')) . "offset=$prevoffset">previous page</a>n";

    }

    $pages = intval($totalrows/$limit);

    if ($totalrows%$limit) {
    $pages++;
    }

    for ($i=1;$i<=$pages;$i++) {
    if (($offset/$limit) == ($i-1)) {
    echo "&nbsp;&nbsp;$i";

    } else {
    $newoffset=$limit*($i-1);
    echo "&nbsp;&nbsp;<a href="$root$archive?id=author" . rawurldecode (rawurlencode('&')) . "offset=$newoffset">$i</a>&nbsp;&nbsp;n";
    }
    }

    if (!((($offset/$limit)+1)==$pages) && $pages!=1) {
    $newoffset=$offset+$limit;
    echo "<a href="$root$archive?id=author" . rawurldecode (rawurlencode('&')) . "offset=$newoffset">next page</a><p>n";

    }

    echo "</FONT></OL><BR></UL>";

    }
    [/code]

    For some reason it only reloads the page when it's suppose to show next results, anyone know a solution for this?

    I tested it also with the original sample but same problem there, it was found at: http://www.phpbuilder.com/columns/rod20000221.php3


    Thanks,
    Toby
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    $newoffset=$limit*($i-1);
    echo " <a href="$root$archive?id=author" . rawurldecode (rawurlencode('&')) . "offset=$newoffset">$i</a> n";
    >>


    Toby,

    Just try the following lines instedof above one and see how it works.

    echo "<a href="$PHP_SELF?offset=$newoffset">$i</a>n";


    <<
    For some reason it only reloads the page when it's suppose to show next results,
    >>


    That means your offset value is not passing properly to the script.

    For testing purpose just print the $offset variable and see wether the value is passing properly or not...
    ---------------


    <<
    The problem is that I want to use "&" in the URL
    >>

    i think you can use "&" with out any rawurldecode() or rawurlencode() functions...

    Good Luck!!




    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. using js return value to create radio buttons
    By jchin006 in forum HTML Programming
    Replies: 0
    Last Post: December 3rd, 2003, 03:12 PM
  2. help with buttons please! :)
    By varial in forum HTML Programming
    Replies: 3
    Last Post: December 1st, 2003, 10:20 AM
  3. submitting form with buttons & input in different frames
    By fog_llama in forum HTML Programming
    Replies: 4
    Last Post: November 20th, 2003, 12:33 PM
  4. Checkboxes and Next/Prev Buttons
    By UrbanDeveloper in forum PHP Development
    Replies: 6
    Last Post: June 6th, 2003, 03:01 AM
  5. radio buttons
    By yoshimitsu in forum HTML Programming
    Replies: 4
    Last Post: May 31st, 2001, 11:54 PM

IMN logo majestic logo threadwatch logo seochat tools logo