Notice: Undefined offset:

currently getting this error:

Notice: Undefined offset: 1 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 2 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 1 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 2 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 1 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 2 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 1 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 2 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 1 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 2 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 1 in g33\inc\blogpost.php on line 31

Notice: Undefined offset: 2 in g33\inc\blogpost.php on line 31

<?php

class BlogPost
{

public $id;
public $title;
public $post;
public $author;
public $tags;
public $datePosted;

function __construct($inId=null, $inTitle=null, $inPost=null, $inPostFull=null, $inAuthorId=null, $inDatePosted=null)
{
	if (!empty($inId))
	{
		$this->id = $inId;
	}
	if (!empty($inTitle))
	{
		$this->title = $inTitle;
	}
	if (!empty($inPost))
	{
		$this->post = $inPost;
	}

	if (!empty($inDatePosted))
	{
		$splitDate = explode("-", $inDatePosted);
		$this->datePosted = $splitDate[1] . "/" . $splitDate[2] . "/" . $splitDate[0];
	}

	if (!empty($inAuthorId))
	{
		$query = mysql_query("SELECT first_name, last_name FROM people WHERE id = " . $inAuthorId);
		$row = mysql_fetch_assoc($query);
		$this->author = $row["first_name"] . " " . $row["last_name"];
	}

	$postTags = "No Tags";
	if (!empty($inId))
	{
		$query = mysql_query("SELECT tags.* FROM blog_post_tags LEFT JOIN (tags) ON (blog_post_tags.tag_id = tags.id) WHERE blog_post_tags.blog_post_id = " . $inId);
		$tagArray = array();
		$tagIDArray = array();
		while($row = mysql_fetch_assoc($query))
		{
			array_push($tagArray, $row["name"]);
			array_push($tagIDArray, $row["id"]);
		}
		if (sizeof($tagArray) > 0)
		{
			foreach ($tagArray as $tag)
			{
				if ($postTags == "No Tags")
				{
					$postTags = $tag;
				}
				else
				{
					$postTags = $postTags . ", " . $tag;
				}
			}
		}
	}
	$this->tags = $postTags;
}

}

?>

This is happening due to accessing wrong index of array variable

$splitDate = explode(“-”, $inDatePosted);
$this->datePosted = $splitDate[1] . “/” . $splitDate[2] . “/” . $splitDate[0];

May be $inDatePosted date is not coming with hypen, so you have to change the code as below, might fix your problem.

$splitDate = explode(“-”, $inDatePosted);
$this->datePosted = (count($splitDate) >= 2) ? ($splitDate[1] . “/” . $splitDate[2] . “/” . $splitDate[0]) : $inDatePosted;

the code worked thanks a lot!!!

what dose this mean?

(count($splitDate) >= 2) ?

That is Ternary form of an if statement.

(condition) ? true : false;

is equivilant to

if (condition) {
true;
} else {
false;
}

(with condition, true, and false being statements and logical tests where appropriate, of course)

count() function will return length of an given array. So we are checking $splitDate having date, month and year.

cool thanks hey StarLion do you have any books that could help me out as much as I like to post here I want to really learn this stuff my self. Like a php for dummies or some thing I got the every easy simple stuff or should I say the straight forward stuff (depending on your opinion of straight forward) But some of this stuff just goes over my head.

Obligatory response: Check out the sitepoint books in the Products section!

Uhm… as far as the very, very basics… the PHP manual is where i do 90% of my referencing. PHP: A simple tutorial - Manual
When I started PHP I had a book; the book was very comprehensive. Comprehensive though isnt what I wanted. I had specific questions, specific problems that I wanted to solve.

Really, it all boils down to how you learn best.

thanks!

The only thing that is displaying is the title.

Here is the index.php code

	<?php
	include ("includes.php");
	
	$blogPosts = GetBlogPosts();
	
	foreach ($blogPosts as $post)
	{
		echo "<div class='blogPost'>";
		echo "<header>";
		echo "<title>" . $post->title . "</title>";
		echo "<span>" . $post->datePosted ."</span>";
		echo "</header>";
		
		echo "<section>";
		echo "<div class='imgBox'>" . $post->img_post . "</div>";
		echo "<div class='noteBox'><p>" . $post->post . "</p></div>";
		echo "</section>";	
		
		echo "<footer>Posted By:" . $post->author . " Tags: " . $post->tags . "</footer>";
		echo "</div>";
	}
	?>

This is the include file:

<?php
include 'blogpost.php';

// Change this info so that it works with your system.
$connection = mysql_connect() or die ("<p class='error'>Sorry, we were unable to connect to the database server.</p>");
$database = "basic";
mysql_select_db($database, $connection) or die ("<p class='error'>Sorry, we were unable to connect to the database.</p>");

function GetBlogPosts($inId=null, $inTagId =null)
{
	if (!empty($inId))
	{
		$query = mysql_query("SELECT * FROM blog_posts WHERE id = " . $inId . " ORDER BY id DESC"); 
	}
	else if (!empty($inTagId))
	{
		$query = mysql_query("SELECT blog_posts.* FROM blog_post_tags LEFT JOIN (blog_posts) ON (blog_post_tags.postID = blog_posts.id) WHERE blog_post_tags.tagID =" . $tagID . " ORDER BY blog_posts.id DESC");
	}
	else
	{
		$query = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");
	}
	
	$postArray = array();
	while ($row = mysql_fetch_assoc($query))
	{
		$myPost = new BlogPost($row["id"], $row['title'], $row['img_post'], $row['post'], $row['postfull'], $row["author_id"], $row['datePosted']);
		array_push($postArray, $myPost);
	}
	return $postArray;
}
?>

This is the blogpost.php

<?php

class BlogPost
{

public $id;
public $title;
public $img_post;
public $post;
public $author;
public $tags;
public $datePosted;

function __construct($inId=null, $inTitle=null, $inPost=null, $inPostFull=null, $inAuthorId=null, $inDatePosted=null)
{
	if (!empty($inId))
	{
		$this->id = $inId;
	}
	if (!empty($inTitle))
	{
		$this->title = $inTitle;
	}
	if (!empty($inPost))
	{
		$this->post = $inPost;
	}

	if (!empty($inDatePosted))
	{
		$splitDate = explode("-", $inDatePosted);
		$this->datePosted = (count($splitDate) >= 2) ? ($splitDate[1] . "/" . $splitDate[2] . "/" . $splitDate[0]) : $inDatePosted;
	}

	if (!empty($inAuthorId))
	{
		$query = mysql_query("SELECT first_name, last_name FROM people WHERE id = " . $inAuthorId);
		$row = mysql_fetch_assoc($query);
		$this->author = $row["first_name"] . " " . $row["last_name"];
	}

	$postTags = "No Tags";
	if (!empty($inId))
	{
		$query = mysql_query("SELECT tags.* FROM blog_post_tags LEFT JOIN (tags) ON (blog_post_tags.tag_id = tags.id) WHERE blog_post_tags.blog_post_id = " . $inId);
		$tagArray = array();
		$tagIDArray = array();
		while($row = mysql_fetch_assoc($query))
		{
			array_push($tagArray, $row["name"]);
			array_push($tagIDArray, $row["id"]);
		}
		if (sizeof($tagArray) > 0)
		{
			foreach ($tagArray as $tag)
			{
				if ($postTags == "No Tags")
				{
					$postTags = $tag;
				}
				else
				{
					$postTags = $postTags . ", " . $tag;
				}
			}
		}
	}
	$this->tags = $postTags;
}

}

?>

there is information in those fields and it connects I’m not getting any errors. The information is not being displayed.

Are you making this system or trying to mod something?

I’m modifying some code that I got. I used it before ans it worked fine now I’m trying to change the style and I added the image section that’s it nothing fancy and it’s not working.