#1
  1. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    i searched this forum and around the net and didn't really find a link navigation script that i liked, so i just created my own

    if you're interested, try it out and let me know what you think, customize the output all you want, right now the output is very basic, let me know if you have any questions or want to show me your implementation of the script
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?php

    // variables
    //--------------------------------------------------------------------------------------
    $limit = 10; // number of records to display
    $connect = "hostname, username, password"; // string to connect to database program
    $db = "databaseName"; // database to use
    $sql = "select * from tableName"; // string to query database
    //--------------------------------------------------------------------------------------

    $PATH_INFO = preg_replace("/^.*/([w.]+)$/", "1", $PATH_INFO);
    $offset = preg_replace("/D/", "", $offset);

    mysql_connect("$connect");
    mysql_select_db("$db");

    $result = mysql_query("$sql");
    $total = mysql_num_rows($result);

    if(!$offset)
    {
    $offset = 0;
    }
    elseif($offset >= $total)
    {
    $offset = $total - $limit;
    }

    $result = mysql_query("$sql limit $offset, $limit");

    while($data = mysql_fetch_array($result))
    {
    // output records
    //-----------------------
    print <<<EOF
    $data[fieldName1]

    <br>
    $data[fieldName2]

    <br>
    $data[fieldName3]

    <br><br>
    EOF;
    //-----------------------
    }

    // create link to previous page
    //---------------------------------------------------------------------
    if($offset <= 0)
    {
    $prevUrl = "<<";
    }
    elseif($offset < $limit && $offset > 0)
    {
    $prevUrl = "<a href="$PATH_INFO?offset=0"><<</a>";
    }
    else
    {
    $prev = $offset - $limit;
    $prevUrl = "<a href="$PATH_INFO?offset=$prev"><<</a>";
    }
    //---------------------------------------------------------------------

    // create link to next page
    //--------------------------------------------------------------------
    $next = $offset + $limit;

    if($next >= $total)
    {
    $nextUrl = ">>";
    }
    else
    {
    $nextUrl = "<a href="$PATH_INFO?offset=$next">>></a>";
    }
    //--------------------------------------------------------------------

    print "<br><br>$prevUrl ";

    // print page links
    //------------------------------------------------------------------------------------
    $numberOfPages = ceil($total / $limit);

    for($i=0; $i<$numberOfPages; $i++)
    {
    if($i * $limit == $offset)
    {
    print ($i + 1)." ";
    }
    else
    {
    print "<a href="$PATH_INFO?offset=".($i * $limit)."">".($i + 1)."</a> ";
    }
    }
    //------------------------------------------------------------------------------------

    print $nextUrl;
    ?>
    [/code]

    [This message has been edited by RyanP (edited August 24, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Quispamsis, NB, Canada
    Posts
    49
    Rep Power
    14
    DAAAAAAAMn!!
    I was just trying to figure out how to do this =) thanks man!
  4. #3
  5. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    no problem, one thing i just noticed is that devshed has taken my escaped less than and greater than symbols for the previous and next links and turned them into actual less than an greater than symbols, something to keep in mind if you copy this

    also, sorry about the line break formatting, devshed seems to only allow one consecutive line break so unfortunately my code is all one line after another

Similar Threads

  1. Replies: 2
    Last Post: February 10th, 2004, 11:03 PM
  2. Codepupil
    By Adachic in forum C Programming
    Replies: 3
    Last Post: February 6th, 2004, 06:50 PM
  3. Creating some type of ASP Hardware Poll
    By darkbird in forum ASP Programming
    Replies: 0
    Last Post: February 4th, 2004, 01:44 PM
  4. Replies: 3
    Last Post: January 31st, 2004, 12:16 AM
  5. How can I enable a power user to run this script?
    By Yamadatroy in forum Visual Basic Programming
    Replies: 2
    Last Post: January 19th, 2004, 09:39 PM

IMN logo majestic logo threadwatch logo seochat tools logo