Jump to content

Very odd, fetch_assoc() array resulting in blank white page


MasterACE14

Recommended Posts

Ok, this is rather bizarre. First this code...

            if($postCount > 0)
            {
                $i = 0;
                while($row = $this->db->fetch_assoc($post_pagination->resource()))
                {
                //    echo $row['post_message'];
                    $content .= ($i % 2 == 0 ? '<tr class="odd">' : '<tr>');
                    $content .= '<table>';
                    $content .= '<tr><td>'.$row['username'].'</td></tr>';
                    $content .= '<tr>';
                    $content .= '<td><p>'.$row['post_message'].'</p></td>';
                    $content .= '</tr>';
                    $content .= '</table>';
                    $content .= '</tr>';
                    $i++;
                }
                $content .= '<tr><td>| '.$plinks.' |</td></tr>';
            }

 

For whatever reason, if I comment out the line with $row['post_message'] everything works as expected. If I leave that in there like it is now, I get a completely blank white page.

 

I've also tried assigning it to a variable within the loop like...

$post_message = $row['post_message'];

and that works fine, until I try echo'ing it then the same blank white page result.

 

I've double checked the query, both in PHP and in PHPMyAdmin and it is working correctly.

 

Here's the query code:

            $post_pagination = new pagination($ppg, "SELECT `posts`.`post_id`, `posts`.`post_message`, `cg_accounts`.`id`, `cg_accounts`.`username`
                                       FROM `".$this->dbname."`.`threads`, `".$this->dbname."`.`posts`
                                       INNER JOIN `crikeyga_central`.`cg_accounts` ON (`cg_accounts`.`id` = `posts`.`userid`)
                                       WHERE `posts`.`thread_id`=`threads`.`thread_id`
                                       AND `posts`.`thread_id`='".$thread_id."'
                                       ORDER BY `posts`.`post_timestamp` ASC");

I've also double checked the pagination class is working as expected, and it's fine in every other page it's used in. Also $ppg is the correct value(simply holds the current page number). $this->dbname is also correct, and as mentioned above the query works in PHPMyAdmin.

 

And $post_pagination->resource() is holding the correct value and I've checked the database class in particular $this->db->fetch_assoc() and that's working fine.

 

Really not having much luck pinning this one down, no errors are coming up(error reporting(E_ALL)).

 

seems strange to me that $row['username'] comes up fine, but $row['post_message'] results in a white page. The values are also what they should be.

 

Any help is appreciated!

 

Thanks, Ace

Link to comment
Share on other sites

Any chance that the content in $row['post_message'] contains some javascrpt that causes the page to redirect to itself w/o some needed value in the URL or a different URL so that you get a blank page for the new http request?

 

What does - echo htmlentities($row['post_message']); show?

 

Link to comment
Share on other sites

Any chance that the content in $row['post_message'] contains some javascrpt that causes the page to redirect to itself w/o some needed value in the URL or a different URL so that you get a blank page for the new http request?

 

What does - echo htmlentities($row['post_message']); show?

 

 

Just plain text is stored.

 

and echo htmlentities shows:

Thread Text…

 

this however results in the blank white page(empty source).

$content .= '<td><p>'.htmlentities($row['post_message']).'</p></td>';

 

And you have error_reporting = -1 and display_errors= On in your php.ini file, right?

yep

Link to comment
Share on other sites

The code on your page is doing something when $content contains either the specific content in that variable or contains some amount of content in that variable.

 

Set $row['post_message'] to some short test string, right before the set of $content .= "..."; statements, to see if the length or the actual content in it changes the symptom.

 

Frankly, this is one of those problems, i.e. a whole page that doesn't work, that we could probably solve easily if we had all the code needed to reproduce the problem, since the suggestions to try would be specific to what the code is doing and not just guesses.

 

What does a phpinfo(); statement show for the error_reporting, display_errors, and output_buffering settings? BTW - having output_buffering on in the php.ini or using it in your code can hide php error messages.

Link to comment
Share on other sites

Set $row['post_message'] to some short test string, right before the set of $content .= "..."; statements, to see if the length or the actual content in it changes the symptom.

set it to 'something' and it displayed it fine.

 

phpinfo():

output_buffering = On
error_reporting = E_ALL 
display_errors = On

 

It's difficult to show the code as it's all a part of my framework, I've got all the required code for this part with the issues but aren't having any luck in recreating the problem. Maybe the SQL schema can shed some light.

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 20, 2011 at 05:12 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `crikeyga_forum`
--

-- --------------------------------------------------------

--
-- Table structure for table `forums`
--

CREATE TABLE IF NOT EXISTS `forums` (
  `forum_id` int(10) NOT NULL AUTO_INCREMENT,
  `cat_id` int(10) NOT NULL,
  `forum_name` varchar(50) NOT NULL,
  `forum_description` varchar(225) NOT NULL,
  `forum_order` int(5) NOT NULL DEFAULT '0',
  `forum_locked` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`forum_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

--
-- Dumping data for table `forums`
--

INSERT INTO `forums` (`forum_id`, `cat_id`, `forum_name`, `forum_description`, `forum_order`, `forum_locked`) VALUES
(1, 1, 'General Discussion', 'talk about anything you like', 2, 0),
(2, 1, 'Announcements', '', 1, 1),
(3, 1, 'Suggestions and Ideas', 'if you have a suggestion or idea, share it here', 3, 0),
(4, 2, 'Announcements', '', 4, 1),
(5, 2, 'General Discussion', 'talk about anything Realm Battles related here', 5, 0),
(6, 2, 'Battle Grounds', '', 6, 0),
(7, 2, 'Recruiting', '', 7, 0),
(8, 2, 'Suggestions and Ideas', 'if you have a suggestion or idea for Realm Battles, share it here', 8, 0),
(9, 2, 'Bugs, Glitches and Exploits', 'if you have discovered something that needs to be fixed, share it here', 9, 0);

-- --------------------------------------------------------

--
-- Table structure for table `posts`
--

CREATE TABLE IF NOT EXISTS `posts` (
  `post_id` int(255) unsigned NOT NULL AUTO_INCREMENT,
  `thread_id` int(255) unsigned NOT NULL,
  `userid` int(225) unsigned NOT NULL,
  `post_message` text NOT NULL,
  `post_timestamp` int(10) NOT NULL,
  PRIMARY KEY (`post_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `posts`
--

INSERT INTO `posts` (`post_id`, `thread_id`, `userid`, `post_message`, `post_timestamp`) VALUES
(2, 2, 2, 'Thread Text…', 1319001229),
(3, 3, 2, 'Thread Text…', 1319001343),
(4, 4, 2, 'Thread Text…', 1319001406);

-- --------------------------------------------------------

--
-- Table structure for table `threads`
--

CREATE TABLE IF NOT EXISTS `threads` (
  `thread_id` int(255) unsigned NOT NULL AUTO_INCREMENT,
  `forum_id` int(10) NOT NULL,
  `thread_name` varchar(125) NOT NULL,
  `thread_lastpost` int(10) NOT NULL,
  `thread_locked` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`thread_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `threads`
--

INSERT INTO `threads` (`thread_id`, `forum_id`, `thread_name`, `thread_lastpost`, `thread_locked`) VALUES
(2, 0, 'test', 1319001229, 0),
(3, 0, 'test', 1319001343, 0),
(4, 0, 'testing', 1319001406, 0);

 

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 20, 2011 at 05:14 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `crikeyga_central`
--

-- --------------------------------------------------------

--
-- Table structure for table `cg_accounts`
--

CREATE TABLE IF NOT EXISTS `cg_accounts` (
  `id` int(255) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(75) NOT NULL,
  `email` varchar(75) NOT NULL,
  `password` varchar(75) NOT NULL,
  `registered` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `activated` enum('true','false') NOT NULL DEFAULT 'false',
  `auth` enum('member','premium','moderator','administrator') NOT NULL DEFAULT 'member',
  `sq` varchar(125) NOT NULL,
  `sqa` varchar(50) NOT NULL,
  `credits` int(255) unsigned NOT NULL DEFAULT '0',
  `lastonline` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `activation_code` varchar(25) NOT NULL,
  `dob` int(10) NOT NULL,
  `aboutme` text NOT NULL,
  `location` varchar(75) NOT NULL,
  `realname` varchar(125) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `cg_accounts`
--

INSERT INTO `cg_accounts` (`id`, `username`, `email`, `password`, `registered`, `activated`, `auth`, `sq`, `sqa`, `credits`, `lastonline`, `activation_code`, `dob`, `aboutme`, `location`, `realname`) VALUES
(1, 'test', 'test@test.com', 'ee4f3ff49c355575449e363a8ce63728', '2011-07-25 22:53:31', 'true', 'member', '', '', 0, '0000-00-00 00:00:00', '', 0, '', '', ''),

 

Trying to recreate the blank page issue...

<?php

error_reporting(E_ALL);

/*******************************************************************************
*                                  Pagination class                            *
*                             Created: 12th January 2009                       *
*                             Updated: 9th September 2009                      *
*                             ©Copyright Jay Gilford 2009                      *
*                              http://www.jaygilford.com                       *
*                            email: jay [at] jaygilford.com                    *
*******************************************************************************/

class pagination
{
    ################################
    # PRIVATE VARS - DO NOT ALTER  #
    ################################
    private $_query = '';
    private $_current_page = 1;
    private $_padding = 2;
    private $_results_resource;
    private $_output;

    ################################
    #       RESULTS VARS           #
    ################################
    public $results_per_page = 10;          #Number of results to display at a time
    public $total_results = 0;              #Total number of records
    public $total_pages = 0;                #Total number of pages

    public $link_prefix = '/?page=';        #String for link to go before the page number
    public $link_suffix = '';               #String for link to go after the page number
    public $page_nums_separator = ' | ';    #String to go between the page number links
    public $link_style = '';                #String to add CSS style/class/id to the links
    public $link_title = '';                #String to add the 'title' attribute with page number for use with AJAX

    ################################
    #      ERROR HOLDING VAR       #
    ################################
    public $error = null;

    ################################
    # PAGINATION TEMPLATE DEFAULTS #
    ################################
    public $tpl_first = '<a href="{link}" {link_style} {title}>«</a> | ';
    public $tpl_last = ' | <a href="{link}" {link_style} {title}>»</a> ';

    public $tpl_prev = '<a href="{link}" {link_style} {title}>‹</a> | ';
    public $tpl_next = ' | <a href="{link}" {link_style} {title}>›</a> ';

    public $tpl_page_nums = '<span><a href="{link}" {link_style} {title}>{page}</a></span>';
    public $tpl_cur_page_num = '<span>{page}</span>';

    /**
     * In the above templates {link} is where the link will be inserted and {page} is
     * where the page numbers will be inserted. Other than that, you can modify them
     * as you please
     *
     * NOTE: You should have a separator of some sort at the right of $tpl_first and
     * $tpl_prev as above in the defaults, and also have a separator of some sort
     * before the $tpl_next and $tpl_last templates
     **/


    ##################################################################################


    public function __construct($page, $query)
    {
        #Check page number is a positive integer greater than 0 and assign it to $this->_current_page
        if ((int)$page > 0)
            $this->_current_page = (int)$page;

        #Remove any LIMIT clauses in the query string and set if
        $query = trim(preg_replace('/[\s]+LIMIT[\s]+\d+([\s,]*,[^\d]*\d+)?/i', '', $query));
        if (empty($query)) {
            return false;
        } else {
            $this->_query = $query;
        }
    }

    /**
     * pagination::paginate()
     *
     * Processes all values and query strings and if successful
     * returns a string of html text for use with pagination bar
     *
     * @return string;
     */
    public function paginate()
    {
        $output = '';

        #########################################
        # GET TOTAL NUMBER OF RESULTS AND PAGES #
        #########################################
        $result = mysql_query($this->_query);
        if (!$result) {
            $this->error = __line__ . ' - ' . mysql_error();
            return false;
        }
        $this->total_results = mysql_num_rows($result);
        $this->total_pages = ceil($this->total_results / $this->results_per_page);

        ########################
        # FREE RESULT RESOURCE #
        ########################

        ################################
        # IF TOTAL PAGES <= 1 RETURN 1 #
        ################################
        if ($this->total_pages <= 1)
        {
        	$this->_results_resource = $result;
		$this->_output = '1';
		return $this->_output;
        }

        mysql_free_result($result);

        ###################################################
        # CHECK CURRENT PAGE ISN'T GREATER THAN MAX PAGES #
        ###################################################
        if ($this->_current_page > $this->total_pages)
            $this->_current_page = $this->total_pages;

        ######################################
        # SET FIRST AND LAST PAGE VALUES AND #
        # ERROR CHECK AGAINST INVALID VALUES #
        ######################################
        $start = ($this->_current_page - $this->_padding > 0) ? $this->_current_page - $this->
            _padding : '1';
        $finish = ($this->_current_page + $this->_padding <= $this->total_pages) ? $this->
            _current_page + $this->_padding : $this->total_pages;

        ###########################################
        # CREATE LIMIT CLAUSE AND ASSIGN TO QUERY #
        ###########################################
        $limit = ' LIMIT ' . ($this->results_per_page * ($this->_current_page - 1)) .
            ',' . $this->results_per_page;
        $query = $this->_query . $limit;

        #############################################
        # RUN QUERY AND ASSIGN TO $_result_resource #
        #############################################
        $result = mysql_query($query);
        if ($result === false) {
            $this->error = __line__ . ' - ' . mysql_error();
            return false;
        }
        $this->_results_resource = $result;

        ###########################################
        # ADD FIRST TO OUTPUT IF CURRENT PAGE > 1 #
        ###########################################
        if ($this->_current_page > 1) {
            $patterns = array('/\{link\}/i', '/\{link_style\}/i', '/\{title\}/i');
            $replaces = array($this->link_prefix . '1' . $this->link_suffix, $this->link_style, 'title="1"');
            $output .= preg_replace($patterns, $replaces, $this->tpl_first);
        }

        ##########################################
        # ADD PREV TO OUTPUT IF CURRENT PAGE > 1 #
        ##########################################
        if ($this->_current_page > 1) {
            $patterns = array('/\{link\}/i', '/\{link_style\}/i', '/\{title\}/i');
            $replaces = array($this->link_prefix . ($this->_current_page - 1) . $this->link_suffix, $this->link_style, 'title="'.($this->_current_page - 1).'"');
            $output .= preg_replace($patterns, $replaces, $this->tpl_prev);
        }

        ################################################
        # GET LIST OF LINKED NUMBERS AND ADD TO OUTPUT #
        ################################################
        $nums = array();
        for ($i = $start; $i <= $finish; $i++) {
            if ($i == $this->_current_page) {
                $nums[] = preg_replace('/\{page\}/i', $i, $this->tpl_cur_page_num);
            } else {
                $patterns = array('/\{link\}/i', '/\{page\}/i', '/\{link_style\}/i', '/\{title\}/i');
                $replaces = array($this->link_prefix . $i . $this->link_suffix, $i, $this->link_style, 'title="'.$i.'"');
                $nums[] = preg_replace($patterns, $replaces, $this->tpl_page_nums);
            }
        }
        $output .= implode($this->page_nums_separator, $nums);

        ##################################################
        # ADD NEXT TO OUTPUT IF CURRENT PAGE < MAX PAGES #
        ##################################################
        if ($this->_current_page < $this->total_pages) {
            $patterns = array('/\{link\}/i', '/\{link_style\}/i', '/\{title\}/i');
            $replaces = array($this->link_prefix . ($this->_current_page + 1) . $this->link_suffix, $this->link_style, 'title="'.($this->_current_page + 1).'"');
            $output .= preg_replace($patterns, $replaces, $this->tpl_next);
        }

        ############################################
        # ADD LAST TO OUTPUT IF FINISH < MAX PAGES #
        ############################################
        if ($this->_current_page < $finish) {
            $patterns = array('/\{link\}/i', '/\{link_style\}/i', '/\{title\}/i');
            $replaces = array($this->link_prefix . $this->total_pages, $this->link_style, 'title="'.$this->total_pages.'"');
            $output .= preg_replace($patterns, $replaces, $this->tpl_last);
        }

        $this->_output = $output;
        return $output;
    }


    /**
     * pagination::padding()
     *
     * Sets the padding for the pagination string
     *
     * @param int $val
     * @return bool
     */
    public function padding($val)
    {
        if ((int)$val < 1)
            return false;

        $this->_padding = (int)$val;
        return true;
    }


    /**
     * pagination::resource()
     *
     * Returns the resource of the results query
     *
     * @return resource
     */
    public function resource()
    {
        return $this->_results_resource;
    }


    /**
     * pagination::__tostring()
     * returns the last pagination output
     *
     * @return string
     */
    function __tostring()
    {
        if (trim($this->_output)) {
            return trim($this->_output);
        }else{
        	return '';
        }
    }
}

class MySQL {

                public $last_query;
                private $connection;
	private $magic_quotes_active;
	private $real_escape_string_exists;
                private $host, $user, $pass, $name;

	function __construct( $host = 'localhost', $user = 'root', $pass = '', $name = '' ) {
                        $this->host = $host;
                        $this->user = $user;
                        $this->pass = $pass;
                        $this->name = $name;
		$this->connection = $this->open_connection();
		$this->magic_quotes_active = get_magic_quotes_gpc();
		$this->real_escape_string_exists = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
	}

	private function open_connection() {
		$this->connection = mysql_connect($this->host, $this->user, $this->pass) or trigger_error('No Database Connection Established: ' . mysql_error(), E_USER_ERROR);
		$db_select = mysql_select_db($this->name,$this->connection) or trigger_error('Database selection failed: ' . mysql_error(), E_USER_ERROR);
	}

	public function close_connection() {
		if(isset($this->connection)) {
			mysql_close($this->connection);
			$this->connection = null;
		}
	}

	public function query($sql) {
		$this->last_query = $sql;
                        $result = mysql_query($sql);
		$result = $this->confirm_query($result);
		return $result;
	}

	public function fetch_array($result_set) {
		return mysql_fetch_array($result_set);
	}

	public function fetch_assoc($result_set) {
		return mysql_fetch_assoc($result_set);
	}

                public function fetch_object($result_set) {
                        return mysql_fetch_object($result_set);
                }

                public function fetch_result($result_set, $num) {
                        return mysql_result($result_set, $num);
                }

	public function num_rows($result_set) {
		return mysql_num_rows($result_set);
	}

	public function insert_id() {
		// get the last id inserted over the current database connection
		return mysql_insert_id();
	}

	public function affected_rows() {
		return mysql_affected_rows();
	}

	public function escape_value( $value ) {
		if( $this->real_escape_string_exists ) { // PHP v4.3.0 or higher
		// undo any magic quote effects so mysql_real_escape_string can do the work
		if( $this->magic_quotes_active ) { $value = stripslashes( $value ); }
			$value = mysql_real_escape_string( $value );
		} else { // before PHP v4.3.0
			// if magic quotes aren't already on then add slashes manually
			if( !$this->magic_quotes_active ) { $value = addslashes( $value ); }
		// if magic quotes are active, then the slashes already exist
		}
                        $value = strip_tags($value);
		return $value;
	}

	private function confirm_query($result) {
		if(!$result) {
			trigger_error('Database query confirm failed: ' . mysql_error(), E_USER_ERROR);
                                return false;
		}
                   return $result;
	}

}

class Forum {	
private $dbname = 'crikeyga_forum';
private $db;

    public function __construct($db) {
        $this->db = $db;
	$_GET['do'] = 'posts:3:1'; // for recreating problem
        $this->GetAction();
        return $this->display;
    }

    private function GetAction() {
        if (isset($_GET['do'])) {
            $_GET['do'] = trim(strip_tags($_GET['do']));
            $do = explode(":",$_GET['do']);
            if(empty($do[1]) || empty($do[2]))
                $do[1] = $do[2] = '';

            switch($do) {
                case $do[0] == "forums":
                    $this->display = $this->DisplayForums($do[1]);
                    break;
                case $do[0] == "posts":
                    $this->display = $this->DisplayPosts($do[1], $do[2]);
                    break;
                case $do[0] == "categories":
                    $this->display = $this->DisplayCategories();
                    break;
                case $do[0] == "threads":
                    $this->display = $this->DisplayThreads($do[1], $do[2]);
                    break;
                case $do[0] == "createthread":
                    $this->display = $this->CreateThread($do[1]);
                    break;
                case $do[0] == "createpost":
                    $this->display = $this->CreatePost($do[1]);
                    break;
                default:
                    $this->display = $this->DisplayCategories();
                    break;
            }
        } else
            $this->display = $this->DisplayCategories();
    }

public function DisplayPosts($thread_id, $ppg) {
            $forum_id = $this->db->escape_value($thread_id);
            if(empty($ppg))
                $ppg = 1;
            $ppg = $this->db->escape_value($ppg);
            $post_pagination = new pagination($ppg, "SELECT `posts`.`post_id`, `posts`.`post_message`, `cg_accounts`.`id`, `cg_accounts`.`username`
                                       FROM `".$this->dbname."`.`threads`, `".$this->dbname."`.`posts`
                                       INNER JOIN `crikeyga_central`.`cg_accounts` ON (`cg_accounts`.`id` = `posts`.`userid`)
                                       WHERE `posts`.`thread_id`=`threads`.`thread_id`
                                       AND `posts`.`thread_id`='".$thread_id."'
                                       ORDER BY `posts`.`post_timestamp` ASC");
            $post_pagination->results_per_page = 10;
            $post_pagination->link_prefix = ':';
            $plinks = $post_pagination->paginate();
            $postCount = $post_pagination->total_results;

            $query2 = $this->db->query("SELECT `threads`.`thread_name`
                                        FROM `".$this->dbname."`.`threads`
                                        WHERE `threads`.`thread_id`='".$thread_id."'
                                        LIMIT 1");
            $content = '';
            $content .= '<table id="forum-hor-zebra" summary="Forums">';
            $content .= '<tbody>';
            if($this->db->num_rows($query2) > 0)
            {
                $thread_name = $this->db->fetch_result($query2, 0);
                $content .= '<th>'.$thread_name.' - Posts</th>';
            } else {
                $content .= '<tr><td style="color: red; text-align: center;">An error has occurred!</td></tr>';
            }
            if($postCount > 0)
            {
                $i = 0;
                while($row = $this->db->fetch_assoc($post_pagination->resource()))
                {
                //    echo $row['post_message'];
               //     $row['post_message'] = 'something';
                    $content .= ($i % 2 == 0 ? '<tr class="odd">' : '<tr>');
                    $content .= '<table>';
                    $content .= '<tr><td>'.$row['username'].'</td></tr>';
                    $content .= '<tr>';
                    $content .= '<td><p>'.$row['post_message'].'</p></td>';
                //    echo htmlentities($row['post_message']);
                    $content .= '</tr>';
                    $content .= '</table>';
                    $content .= '</tr>';
                    $i++;
                }
                $content .= '<tr><td>| '.$plinks.' |</td></tr>';
            }
            $content .= '</tbody>';
            $content .= '</table>';
        return $content;
    }
}

$db = new MySQL('localhost', 'root', '', 'crikeyga_central');
$forum = new Forum($db);
echo $forum->DisplayPosts(3, 1);

?>

 

Thanks everyone for your help so far.

Link to comment
Share on other sites

All indications are that something in your actual full code, after the point where the DisplayPosts() method gets called up to where you decide to output anything on the page, is either die'ing or skipping over everything due to a false conditional statement or a false loop condition. I'm going to guess that you have some code that displays a short part of a long post with a 'more' link and that there's a length comparison that is coded wrong.

 

P.S. You cannot return a value/string in the constructor of a class and your forum class doesn't have a $display property/variable so all the code that makes use of $this->display won't do anything.

Link to comment
Share on other sites

Ok I have got it working, it appears it didn't like the data contained in post_message. I'm unsure of why so I'll post whatever data is relevant.

 

Firstly when creating a post, this is the form:

                        $content .= '<table id="forum-hor-zebra" summary="Forums">';
                        $content .= '<tbody>';
                        $content .= '<form action="index.php?cg=cgs&page=forum&do=createthread:'.$forum_id.'" method="post">';
                        $content .= '<th>Create Thread</th>';
                        $content .= '<tr class="odd">';
                        $content .= '<td>Thread Title: <input type="text" name="title" /></td>';
                        $content .= '</tr>';
                        $content .= '<tr>';
                        $content .= '<td><textarea name="text" cols="45" rows="5" wrap="soft" style="width: 98%; padding: 2px;">Thread Text...</textarea></td>';
                        $content .= '</tr>';
                        $content .= '<tr class="odd">';
                        $content .= '<td style="text-align: center;"><input type="submit" name="submit" value="Create Thread" /></td>';
                        $content .= '</tr>';
                        $content .= '<input type="hidden" name="forum_id" value="'.$forum_id.'" />';
                        $content .= '</form>';
                        $content .= '</tbody>';
                        $content .= '</table>';

notice in the textarea I have the default value of "Thread Text...", which is the data that was making the page completely blank. I'm not sure why that particular string could do that?

 

Here's the table structure and that particular record:

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 21, 2011 at 03:42 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `crikeyga_forum`
--

-- --------------------------------------------------------

--
-- Table structure for table `posts`
--

CREATE TABLE IF NOT EXISTS `posts` (
  `post_id` int(255) unsigned NOT NULL AUTO_INCREMENT,
  `thread_id` int(255) unsigned NOT NULL,
  `userid` int(225) unsigned NOT NULL,
  `post_message` text NOT NULL,
  `post_timestamp` int(10) NOT NULL,
  PRIMARY KEY (`post_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `posts`
--

INSERT INTO `posts` (`post_id`, `thread_id`, `userid`, `post_message`, `post_timestamp`) VALUES
(5, 5, 2, 'Thread Text…', 1319166277);

I'm going to take a stab in the dark here, Web Browsers change three ellipsis into one character?

 

I've noticed just now even in this post, there's a difference between the above and typing three ellipsis:

...

 

If that's the case, why would appending it to my $content string break the code, and when it's on it's own it displays fine?

$content .= '<p>'.$row['post_message'].'</p>'; // creates the blank white page
echo $row['post_message']; // works fine

 

Also I find it odd, that code I posted in my previous post to try and recreate the error, works completely fine and it's using the exact same database and it's also being run locally. I can't explain that one.

 

Cheers.

Link to comment
Share on other sites

I've got a feeling that may have something to do with my output buffering and custom post processing function.

<?php

function ob_postprocess($buffer) {
        $buffer = trim(preg_replace('/\s+/', ' ', $buffer));
// add styled double quotes
$buffer = preg_replace('/"(?=[^>]*<)([^"]*)"(?=[^>]*<)/u', '“\\1”', $buffer);
// add ellipses
$buffer = str_replace('...', '…', $buffer);
// encode ampersands
$buffer = str_replace(' & ', ' & ', $buffer);
// check if the browser accepts gzip encoding. Most do, but just in case
return $buffer;
}

function print_compressed_page() {
    global $HTTP_ACCEPT_ENCODING;
    if( headers_sent() ) {
        $encoding = false;
    } elseif( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false ) {
        $encoding = 'x-gzip';
    } elseif( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false ) {
        $encoding = 'gzip';
    } else {
        $encoding = false;
    }

    if( $encoding ){
        $contents = ob_get_contents();
        ob_end_clean();
        header('Content-Encoding: '.$encoding);
        print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
        $size = strlen($contents);
        $contents = gzcompress($contents, 9);
        $contents = substr($contents, 0, $size);
        print($contents);
        exit();
    } else {
        ob_end_flush();
        exit();
    }
}

?>

 

Then the end of my index.php is:

$tpl = new Template();
// start output buffering at the top of our script with this simple command
// we've added "ob_postprocess" (our custom post processing function) as a parameter of ob_start
ob_start('ob_postprocess');
ob_implicit_flush(0);

// place the page content into the output buffer
$tpl->display($page,$template,$content);

// end output buffering and send our content to the browser
print_compressed_page();

Link to comment
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.