...

View Full Version : i got an issue with php script



maxwel
01-30-2012, 02:38 PM
these are the error

Notice: Undefined offset: 1 in /public_html/wp-content/themes/Aggregate/includes/featured.php on line 65

Notice: Undefined offset: 2 in /public_html/wp-content/themes/Aggregate/includes/featured.php on line 65


this is the php code


<div id="controllers" class="clearfix">
<ul>
<?php for ($i = 0; $i < $featured_num; $i++) { ?>
<li>
<div class="controller">
<a href="#"<?php if ( $i == 0 ) echo ' class="active"'; ?>>
<?php print_thumbnail( $arr[$i]['thumbnail']['thumb'], $arr[$i]['thumbnail']["use_timthumb"], $arr[$i]['titletext'], $small_width, $small_height ); ?>
<span class="overlay"></span>
</a>
</div>
</li>
<?php } ?>
</ul>
<div id="active_item"></div>
</div> <!-- end #controllers -->

this is line 65 which got the issue



<?php print_thumbnail( $arr[$i]['thumbnail']['thumb'], $arr[$i]['thumbnail']["use_timthumb"], $arr[$i]['titletext'], $small_width, $small_height ); ?>

Fou-Lu
01-30-2012, 02:41 PM
Where is $arr created? According to this, you have no offsets in $arr under 1 or 2, and assuming its numeric offsets, this indicates that $arr is capped at 1 item within its array regardless of what $featured_num has to say.
To fix it, use a loop with this:


<?php
$iCnt = count($arr);
for ($i = 0; $i < featured_num && $i < $iCnt; ++$i)
?>

mlseim
01-30-2012, 02:42 PM
That's a "notice", not a fatal error.
You can suppress those if you want.

It's telling you that perhaps you're displaying an array item that is null,
or never defined. Example, $arr[6]['thumbnail']['thumb'] was never given a value,
or it doesn't exist.

Your script can still function, but it's just giving you "heads-up" that something isn't right.

maxwel
01-30-2012, 02:56 PM
Here is the whole code in the page n yea there is an arr var there


<div id="featured">
<a id="left-arrow" href="#"><?php _e('Previous','Aggregate'); ?></a>
<a id="right-arrow" href="#"><?php _e('Next','Aggregate'); ?></a>

<div id="slides">
<?php global $ids;
$ids = array();
$arr = array();
$i=0;

$featured_cat = get_option('aggregate_feat_cat');
$featured_num = get_option('aggregate_featured_num');

if (get_option('aggregate_use_pages') == 'false') query_posts("showposts=$featured_num&cat=".get_cat_ID($featured_cat));
else {
global $pages_number;

if (get_option('aggregate_feat_pages') <> '') $featured_num = count(get_option('aggregate_feat_pages'));
else $featured_num = $pages_number;

query_posts(array
('post_type' => 'page',
'orderby' => 'menu_order',
'order' => 'ASC',
'post__in' => get_option('aggregate_feat_pages'),
'showposts' => $featured_num
));
} ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
global $post; ?>
<div class="slide">
<?php
$width = 958;
$height = 340;
$small_width = 95;
$small_height = 54;
$titletext = get_the_title();

$thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,false,'Featured');

$arr[$i]['thumbnail'] = get_thumbnail($small_width,$small_height,'',$titletext,$titletext,false,'Small');
$arr[$i]['titletext'] = $titletext;

$thumb = $thumbnail["thumb"];
print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, ''); ?>
<div class="featured-top-shadow"></div>
<div class="featured-bottom-shadow"></div>
<div class="featured-description">
<p class="meta-info"><?php _e('Posted','Aggregate'); ?> <?php _e('by','Aggregate'); ?> <?php the_author_posts_link(); ?> <?php _e('on','Aggregate'); ?> <?php the_time(get_option('aggregate_date_format')) ?></p>
<h2 class="featured-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><?php truncate_post(410); ?></p>
<a href="<?php the_permalink(); ?>" class="readmore"><?php _e('Read More', 'Aggregate'); ?></a>
</div> <!-- end .description -->
</div> <!-- end .slide -->
<?php $ids[] = $post->ID; $i++; endwhile; endif; wp_reset_query(); ?>
</div> <!-- end #slides -->
</div> <!-- end #featured -->

<div id="controllers" class="clearfix">
<ul>
<?php for ($i = 0; $i < $featured_num; $i++) { ?>
<li>
<div class="controller">
<a href="#"<?php if ( $i == 0 ) echo ' class="active"'; ?>>
<?php print_thumbnail( $arr[$i]['thumbnail']['thumb'], $arr[$i]['thumbnail']["use_timthumb"], $arr[$i]['titletext'], $small_width, $small_height ); ?>
<span class="overlay"></span>
</a>
</div>
</li>
<?php } ?>
</ul>
<div id="active_item"></div>
</div> <!-- end #controllers -->

maxwel
01-30-2012, 03:17 PM
i still need help :S this notice is all over ma site :/ can sumone take a look please and tell me what should be done?

Fou-Lu
01-30-2012, 03:23 PM
i still need help :S this notice is all over ma site :/ can sumone take a look please and tell me what should be done?

I've already posted what you have to do. You always need to check if you are stepping beyond the bounds of the array when you are attempting to access it.

mlseim
01-30-2012, 03:23 PM
When you get to this part ... stop and display the value of $featured_num


<div id="controllers" class="clearfix">
<ul>
echo "featured_num: $featured_num";
exit;
<?php for ($i = 0; $i < $featured_num; $i++) { ?>


Tell us what that number is.

maxwel
01-30-2012, 03:36 PM
it don't show any values thats what it show "echo "featured_num: $featured_num"; exit;"

mlseim
01-30-2012, 03:40 PM
oops ... my bad ...

<div id="controllers" class="clearfix">
<ul>
<?php
echo "featured_num: $featured_num";
exit;
?>
<?php for ($i = 0; $i < $featured_num; $i++) { ?>



.

maxwel
01-30-2012, 03:44 PM
no bro its my bad rofl. its hard dealing with the php :X with no experience lol

here is the number "featured_num: 3"

mlseim
01-30-2012, 08:16 PM
How many featured items do you have?

Do you have 3 of them?

If you have three of them, your loop is going like this ...

0,1,2

Because $i starts at zero.
Arrays start at zero (0).

But do you have an item zero(0)?
Or are your items numbered 1,2,3 ?

Perhaps $arr[0]['thumbnail']['thumb'] does not exist (thus the index error).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum