Jump to content

Links in chronological section


zyrolasting

Recommended Posts

Hello folks. I am a PHP and PHPFreaks newbie using WAMP. ( PHP 5.3, Apache 2.2 )

 

I have successfully set up a system using MySQL to display the latest entry in a blog, news sections, etc.

 

However, I need to make 4 links to navigate the table: First, Previous, Next, Last. I figured I could just toss the links right in with no href and use PHP's DOM, but I look at the manual and realize I can't tell if PHP uses DOM only to reliably create new pages or edit the one I'm on. If I make a new DOMDocument, I can't tell if I literally made a blank one or got access to the current one like in JS.

 

I just need to write code that keeps track of the current entry I'm on and updates the href attributes on the anchors on the page. Here's the code where I stand so far. I honestly do not know where to go from here. I don't need a really definitive answer, just a push in the right direction so I know what I'm doing.

 

<?php
class chron
{
    var $con;

    function __contruct()
    {
	// Connect to MySQL database
        $this->con = mysql_connect(<HOST>,<USERNAME>,<PASSWORD>);
        if ( !$this->$con )
        {
        	die( 'Could not establish connection to MySQL database: ' . mysql_error());
        }

	mysql_select_db( "zyrolasting", $this->$con );		
}
    
function __destruct()
{
    		mysql_close($this->$con);
}

    
    function dispLatest($type)
    {
	try
	{

	// Grab all entries from table ordered where latest entry is first
		$result = mysql_query("SELECT * FROM zyrolasting." . $type . "ORDER BY id DESC");

		if ( !$result )
		{
			throw new Exception('Could not obtain result set.');
		}

		$row = mysql_fetch_array( $result );
		if ( !$row )
		{
			throw new Exception('Could not obtain latest entry.');
		}

		// Num is the number of entries... Needs to be used for links somehow.
		$num = $row['id'];
	}
	catch(Exception $e)
	{
			die( $e->getMessage() . ' Type: ' . $type . ' Error: ' . mysql_error());
	}


// Links go here.

// Display content.
        echo '<h1 class="centerHead">' . $row['title'] 	    . '</h1>'; 
        echo '<h3 class="centerHead">' . $row['datePosted'] . '</h3>'; 
        
        echo $row['content'];
    }
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/178461-links-in-chronological-section/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.