Page 1 of 1

These 2 program should give same output. What am I missing?

Posted: Tue Sep 21, 2010 1:08 am
by raul_8
The only difference is that the 2nd program is written within a function and returns instead of echo. What is the problem?

Code: Select all

<?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;
  }
Following is the second program

Code: Select all

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;
 
}

Re: These 2 program should give same output. What am I missi

Posted: Tue Sep 21, 2010 1:56 am
by requinix
raul_8 wrote:The only difference is that the 2nd program is written within a function and returns instead of echo.
If that was the only difference then there wouldn't be a problem, would there?

0. First script prints the getcwd(). Sure you knew that already.
1. Different $url in both scripts.
2. Just declaring a function does not mean it will be executed (read: make sure you echo'd what the function returned).
3. The first script doesn't have the closing </ul> and </div>

There's also a disturbing lack of information about which one of those actually works and what output you receive with the other.

Re: These 2 program should give same output. What am I missi

Posted: Tue Sep 21, 2010 3:58 am
by raul_8
Ok,
0.Sorry for missing info....First code is working properly.
1.Ignore where the $url are set to.
2.Function is executig...I didn't put the entire code...just the relevant part.
3. Sorry I missed <ul> <div>

Here is the full code:

Code: Select all

<?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>";
 
?>