Jump to content

Last Forum Posts


Go to solution Solved by Ch0cu3r,

Recommended Posts

Hey! So, I don't know if this is the current section, couldn't really decide on what section/board to post it, so .. 

 

I've got a code that I got from a friend of mine (it was a gaming website (a game server), but he shut it down, I asked for some scripts, he sent me the whole site ..). I got all other scripts correctly, but I do not know how to get this Last Forum Posts to work (IP.Board). I've got the SEO set up as it should and everything, doesn't work.

 

When I use this

<?php
	$_handlerForum = new mysql("Forum","localhost","*********_fqipb2","*********_fqipb2","password");
	
	$topics = $_handlerForum->fetch("SELECT `tid`,`title`,`last_post`,`title_seo`,`last_poster_name` FROM `topics` ORDER BY `last_post` DESC LIMIT 0,3;",array());

	$content = "";

	foreach($topics as $topic) {
		$content .= "<a href='http://website.com/forum/index.php?/topic/".$topic['tid']."-".$topic['title_seo']."' target='_blank'>".$topic['title']."</a><br />
			<small class='dim'>".$topic['last_poster_name']." - ".date("H:i F d, Y",$topic['last_post'])."</small><hr style='margin: 5px 0px;' />";
	}
	
	return $content;
	
	return "Under Construction";
?>

I get this error

Fatal error: Class 'mysql' not found in /home/***/***/***/public_html/extra/forum.php on line 2

Thought that the problem was "new mysql" (on line 2), so I put in mysql_connect, still get an error. Can anyone help?

Link to comment
https://forums.phpfreaks.com/topic/290690-last-forum-posts/
Share on other sites

What is with the use of return on the lines 13 & 15?

 

return is not used for outputting something to the browser. It is usually used for returning data from a custom defined/callback function.

 

To output something you need to use echo or print

 

Well, I'm not the one who made the script and I'm not that good at php, so .. :/ Would you be able to .. help me make this script work? Currently, it is

<?php
		class mysql {
		protected $_name;

		protected $_hostname;
		protected $_database;
		protected $_username;
		protected $_password;

		protected $_handle = null;

		public function __construct($name = null,$hostname = null,$database = null,$username = null,$password = null) {
			$this->_name		= $name;
			$this->_hostname	= $hostname;
			$this->_database	= $database;
			$this->_username	= $username;
			$this->_password	= $password;
		}

		public function __call($method, $args){
			if (!$this->_handle)
				$this->connect();

			return call_user_func_array(array($this, $method), $args);
		}


		function connect() {			
			try {
				$this->_handle = new PDO("mysql:host={$this->_hostname};dbname={$this->_database}",$this->_username,$this->_password);		
				$this->_handle->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
				$this->_handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				
			} catch (PDOException $e) {
				$this->error($e->getMessage());
				return false;
			}
		}

		function error($error) {
			$file = fopen(PATH_ROOT."error_log.txt","a");
			fwrite($file,date("H:i:s d/m/Y",time()).": ".$error." (".$_SERVER['REMOTE_ADDR'].")\r\n");
			fclose($file);
		}

		protected function select($query,$array) {
			if (!$this->_handle) return;
			
			try {
				$statement = $this->_handle->prepare($query);
				$statement->execute($array);
				return $statement->fetch();
			} catch (PDOException $e) {
				$this->error($e->getMessage());
				return false;
			}
		}

		protected function fetch($query,$array) {
			if (!$this->_handle) return;
			
			try {
				$statement = $this->_handle->prepare($query);
				$statement->execute($array);
				return $statement->fetchAll();
			} catch (PDOException $e) {
				$this->error($e->getMessage());
				return false;
			}
		}

		protected function execute($query,$array) {
			if (!$this->_handle) return;
			
			try {
				$statement = $this->_handle->prepare($query);
				return $statement->execute($array);
			} catch (PDOException $e) {
				$this->error($e->getMessage());
				return false;
			}
		}

		protected function exec($query,$array) {
			if (!$this->_handle) return;
			
			try {
				$statement = $this->_handle->prepare($query);
				$statement->execute($array);
				return $statement->rowCount();
			} catch (PDOException $e) {
				$this->error($e->getMessage());
				return false;
			}
		}
	}
	
	$_handlerForum = new mysql("Forum","localhost","*********_fqipb2","*********_fqipb2","password");
	
	$topics = $_handlerForum->fetch("SELECT `tid`,`title`,`last_post`,`title_seo`,`last_poster_name` FROM `topics` ORDER BY `last_post` DESC LIMIT 0,3;",array());

	$content = "";

	foreach($topics as $topic) {
		$content .= "<a href='http://website.com/forum/index.php?/topic/".$topic['tid']."-".$topic['title_seo']."' target='_blank'>".$topic['title']."</a><br />
			<small class='dim'>".$topic['last_poster_name']." - ".date("H:i F d, Y",$topic['last_post'])."</small><hr style='margin: 5px 0px;' />";
	}
	
	return $content;
	
	return "Under Construction";
?>
Link to comment
https://forums.phpfreaks.com/topic/290690-last-forum-posts/#findComment-1489097
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.