i am working on codigniter . i am developing basic cms.my view code of generating dynamic pages at front end is

<ul id="jsddm">
<?php for ($i=1; $i<=$url['10']['10']['10']; $i++)
{ ?>
    <li><a href="<?php echo site_url($url[$i]['0']['slug']); ?>"> <?php echo $url[$i]['0']['page_name']; ?> </a>
                  <?php if($url['11'][$i]['11']>0){ ?>
        <ul>
                        <?php for ($j=1; $j<$url['11'][$i]['11']; $j++) { ?>
            <li><a href="<?php echo site_url($url[$i]['0']['slug'].'/'.$url[$i][$j]['slug']) ?>"><?php echo $url[$i][$j]['page_name']; ?></a></li>
                    <?php } ?>
        </ul>
                 <?php } ?>
</li>
<?php }?>
</ul>

It is giving the error

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 9

Filename: includes/website_header.php

Line Number: 85

AND

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 9

Filename: includes/website_header.php

Line Number: 86

the 86th line is if statement.

Sounds like the array doesn't have an index with value 9. Try changing line 5 above to:

<?php if(isset($url['11'][$i]['11']) && $url['11'][$i]['11']>0){ ?>

And if you're using PHP conditional statements inline with HTML, I find the following statements easier to read than tracking brackets:

<?php if(true): ?>
    <!-- Your HTML here -->
<?php endif; ?>

<?php for($i = 0, $count = count($array); $i < $count; $i++): ?>
    <!-- Your HTML here -->
<?php endfor; ?>

<?php foreach($array as $key => $value): ?>
    <!-- Your HTML here -->
<?php endforeach; ?>

Edited 4 Years Ago by blocblue

Yes,The problem of line 86 has been solved thanks for it but the problem of line 85(which is fourth line of the above code) is remaining.....

Edited 4 Years Ago by daniel36

This article has been dead for over six months. Start a new discussion instead.