The only difference is that the 2nd is written within a function and returns instead of echo. What is the problem?
<?php
jcarousel_add('tango');
drupal_add_js (
'$(document).ready(function(){
$("#carousel-cars").jcarousel();
}
); ',
'inline'
);
echo getcwd();
echo "<div id=\"carousel-cars-horiz\">";
echo "<ul id=\"carousel-cars\" class=\"jcarousel-skin-tango\">";
$pic = NULL;
$url = "./sites/all/modules/img/Images/";
$handle = opendir($url);
while (false !== ($file = readdir($handle))) {
if($file != '.' && $file != '..' && $file != 'Thumbs.db') {
$str= "<li><img src =\"" . $url.$file . "\" width=90 height=80/></li>";
echo $str;
}
}
echo "</ul>";
echo "</div>";
?>
Following is the second program
function jcrl($catname) {
jcarousel_add('tango');
drupal_add_js (
'$(document).ready(function(){
$("#carousel-cars").jcarousel();
}
); ',
'inline'
);
$renderjcrl =NULL;
$renderjcrl = $renderjcrl . '<div id=\"carousel-cars-horiz\">';
$renderjcrl = $renderjcrl . '<ul id=\"carousel-cars\" class=\"jcarousel-skin-tango\">';
$pic = NULL;
$url = "./sites/all/Categories/" . $catname . "/";
$handle = opendir($url);
while (false !== ($file = readdir($handle))) {
if($file != '.' && $file != '..' && $file != 'Thumbs.db') {
$renderjcrl = $renderjcrl . "<li><img src =\"" . $url.$file . "\" width=90 height=80/></li>";
}
}
$renderjcrl = $renderjcrl . '</ul>';
$renderjcrl = $renderjcrl . '</div>';
return $renderjcrl;
}