Pagenation Help

Started on the old forum in October 2008 · view the original in the archive · old links redirect here

6 replies · 360 views · started 18 years ago · 2 min read

2 participants
learner Lead · 587 posts #1

hi friends i try to add a next and previous here real coding

class NewsScript
{
    var $maxLength,
        $lim,            /* Num items to show */
        $template,        /* Template to use */
        $db_name,        /* DB Settings */
        $db_host,
        $db_user,
        $db_password,
        $connection;
    
    /**
     * Constructor, executed when we make a new object.
     *
     * @return NewsScript Object
     */
    function NewsScript()
    {
        // Import Database settings etc.
        require('config.php');
        
        $this->db_host = $db_host;
        $this->db_name = $db_name;
        $this->db_user = $db_user;
        $this->db_password = $db_password;
        $this->lim = $lim;
        $this->template = $template;
    }
    
    /**
     *    Display ALL news articles
     *
     */
    function displayAll()
    {
        $this->connect();
        
        // Use the limit in our settings to decide how many to show
        $result = mysql_query("SELECT * FROM news ORDER BY date DESC LIMIT 0, $this->lim");
        
        /* While we have more rows display them */
        while($row = mysql_fetch_assoc($result))
        {
            // Display the row
            $id = $row['id'];
            $author =  $row['author'];
            $content = $row['content'];
            $date = $this->convertDate($row['date']);
            
            /*
            Variables are used in the template file to display news info
            */
            require($this->template);
            
        }
        
        $this->close();
    }
    
    /**
     * Display a single news item given it's ID.
     *
     * @param $id - ID of item to display
     * @return true/false
     */
    function displayItem($id)
    {
        if(is_numeric($id))
        {
            $this->connect();
            
            $result = mysql_query("SELECT * FROM newstbl WHERE id = '$id'");
            $row = mysql_fetch_assoc($result);
            
            $author =  $row['author'];
            $content = $row['content'];
            $date = $this->convertDate($row['date']);
            
            require($this->template); // Show item with our template.
            
            $this->close();
            return true;
        }
        else return false; // Not valid number
        
    }

here i try my coding

class NewsScript
{
    var $maxLength,
        $lim,            /* Num items to show */
        $template,        /* Template to use */
        $db_name,        /* DB Settings */
        $db_host,
        $db_user,
        $db_password,
        $connection;
    
    /**
     * Constructor, executed when we make a new object.
     *
     * @return NewsScript Object
     */
    function NewsScript()
    {
        // Import Database settings etc.
        require('config.php');
        
        $this->db_host = $db_host;
        $this->db_name = $db_name;
        $this->db_user = $db_user;
        $this->db_password = $db_password;
        $this->lim = $lim;
        $this->template = $template;
    }
    
    /**
     *    Display ALL news articles
     *
     */
    function displayAll()
    {
        $this->connect();

        
if ($_GET['page']==NULL){
$start = 0;
} else {
$start = $_GET['page'];
}

// the if above, states that if the variable in the URL named page has a value, $start will be set to it, otherwise by default it is set to 0, meaning that it will start at the beginning of the table by default.

if($_GET['page'] < 0){
header("Location: http://site.com/news.php?page=0&lim=".$lim);
}

        // Use the limit in our settings to decide how many to show
        $result = mysql_query("SELECT * FROM news ORDER BY date DESC LIMIT 0, $this->lim");
        
        /* While we have more rows display them */
        while($row = mysql_fetch_assoc($result))
        {
            // Display the row
            $id = $row['id'];
            $author =  $row['author'];
            $content = $row['content'];
            $date = $this->convertDate($row['date']);

            
            /*
            Variables are used in the template file to display news info
            */
            require($this->template);

            
        }
        

$previous = $start + $lim;
$next = $start - $lim;
echo "<div align='center'>
     <a href='http://site.com/news.php?start=".$previous."'>Previous Page</a> - 
     <a href='http://site.com/news.php?start=".$next."'>Next Page</a>
         </div>
";

        $this->close();

    }

but no result not work 🙁 help me add please, in the config file lim is add 10 so 10 messages showing in 1 page nomatter how much i dd only 10 show i want to show all help 😛

Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

BEST MOBILE ADVERTISER

External image (may be gone)

Guest #3

You are poor in class...try class less script, ...............there are too many errors ...1 i can say

header("Location: http://site.com/news.php?page=0&lim=".$this->lim);
learner Lead · 587 posts #6

anyway problem solved i make myslf that pagination without help from anybody. i say one thing rukiya bro do not be angry u have help me many time and im greatful but u make fun of others that is very bad never have ego coz that destory

Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

BEST MOBILE ADVERTISER

External image (may be gone)

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close