Jump to content

My PHP class isn't displaying right in HTML


scrubbicus

Recommended Posts

index.php

 

if($module->positionExist('featured')) {

  $module->getFeatured('recent','recent','recent');

}

 

modules.php

 

public function getFeatured($one, $two, $three) {

  $toLoop = array('one' => $one, 'two' => $two, 'three' => $three);

  echo '<div id="featured">';

  foreach($toLoop as $class => $featured) {

  echo '<div id="feature" class="'.$class.'">

        '.self::getModule($featured).'

        </div>';

  }

echo '</div>';

}

 

the class that's getting called to display information

 

} elseif($assoc['type'] == 'articles') {

if($results = mysql_query('SELECT * FROM '.$assoc['type'].'')) {

while($row = mysql_fetch_array($results)) {

if($row['published'] == 1) {

$menu[] = $row[1];

}

}

 

if($name == 'recent') {

echo '<div id="recent"> <span class="header"> » Recent News </span> <ul>';

foreach($menu as $item) {

echo '<li> <a href="?page='.$item.'.php"> <span>'.ucwords($item).'</span>

</a> </li>';

}

echo '</ul> </div>';

}

}

 

What's happening is the first one that appears does not go in the <div id="feature" class="one"> it doesn't go in anything, then the next two do appear as they are suppose to but because of the first one the page doesn't look right.

 

The CSS and everything works like it should. I tested it out in basic HTML without trying the classes.

 

I put into some hard code words in the getFeatured right before it calls the class and right after the div starts and that works just fine so it seems like the problem is when it calls self::getModule(), I went into the getModule() and got rid of any code there and told it to just echo the words hello and that did not appear like it should, it appeared outside the <div>. So it's definitely where it calls self::getModule() just can't understand why.

I can tell you why the echo "hello" didn't work.

<?php
echo '<div id="feature" class="'.$class.'">
         '.self::getModule($featured).'
         </div>';   
?>

The command "echo" is expecting a value returned to it from self::getModule() which it will then place within its string: ie '<div id="feature" class="$class">{return val from getModule}</div>' .

getModule() isn't returning a value, it is just echoing "hello". Amusingly, it executes its echo before the outer echo. So, "hello" ends up in front of the div, while the div ends up empty. Instead of echo "hello" in getModule(), you want to return "hello". That will solve that problem.

Archived

This topic is now archived and is closed to further replies.

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