| 
	    
         By: Manos 
        Date: 2009-09-06 
        Time: 20:16 
		
	   | 
	  
      
	    Can anyone help with that? ondata=customfunc
        
        Hello, 
im having a problem using the custom function on the ondata event. 
i have the following array in a file called thearray.php
 
$test = array( 
1 => "blue", 
2 => "green", 
3 => "red", 
4 => "white" 
); 
 |  
  
which i include in my script that loads the template. Here is the script:
 
require_once('testdir/thearray.php'); 
 
function getColor($BlockName,&$CurrRec,$RecNum) { 
    $CurrRec['color_name'] = $test[$CurrRec['colorId']]; 
} 
 
$tbs = new clsTinyButStrong; 
$tbs->LoadTemplate('tpl/home.html'); 
$tbs->MergeBlock('colorlist', 'tbssql', 'SELECT id FROM colors'); 
$tbs->Show(); 
 |  
  
On the HTML side i have the following:
 
<ul> 
  <li class="arrow"> 
    <a href="showColors.php?colId=[colorlist.id;block=li;ondata=getColorName]">[colorlist.color_name] 
    </a> 
  </li> 
</ul> 
 |  
  
When i run this im getting no color names.
 
After some tests i figured that my function doesnt see the array (out of scope maybe??)
 
The goal is to translate the color ids that i keep in the DB with the color names that i keep in a PHP array. Finally show a list of color names on the page based on the color ids.
 
Any clue what im doing wrong or how to achieve this?
 
Thanks anyway!  
	   | 
	  
    
	
      | 
	    
         By: Manos 
        Date: 2009-09-06 
        Time: 20:31 
		
	   | 
	  
      
	    Re: Can anyone help with that? ondata=customfunc
        
        2 corrections, sorry for that.. 
I forgot to say that i also include the following files in the script:
 
require_once('inc/dbConfig.php'); 
require_once('inc/tbs.php'); 
 |  
  
and a correction in the function code, 
 
function getColor($BlockName,&$CurrRec,$RecNum) { 
   $CurrRec['color_name'] = $test[$CurrRec['id']]; 
} 
 |  
  
The correct script looks like this
 
require_once('inc/dbConfig.php'); 
require_once('inc/tbs.php'); 
require_once('testdir/thearray.php'); 
 
function getColor($BlockName,&$CurrRec,$RecNum) { 
   $CurrRec['color_name'] = $test[$CurrRec['id']]; 
} 
 
$tbs = new clsTinyButStrong; 
$tbs->LoadTemplate('tpl/home.html'); 
$tbs->MergeBlock('colorlist', 'tbssql', 'SELECT id FROM colors'); 
$tbs->Show(); 
 |  
  
I tested the db connection and works fine. I cant see what am i missing here :-|  
	   | 
	  
    
	
      | 
	    
         By: TomH 
        Date: 2009-09-07 
        Time: 01:49 
		
	   | 
	  
      
	    Re: Can anyone help with that? ondata=customfunc
        
        You have ondata=getColorName 
 
...but you have function getColor() 
 
Is that correct 
	   | 
	  
    
	
      | 
	    
         By: Manos 
        Date: 2009-09-07 
        Time: 08:31 
		
	   | 
	  
      
	    Re: Can anyone help with that? ondata=customfunc
        
        You are right. I checked it and i had this correct on my server. Still i get nothing when i merge block. 
 
Can anyone suggest a solution on how to do this? 
	   | 
	  
    
	
      | 
	    
         By: TomH 
        Date: 2009-09-07 
        Time: 12:16 
		
	   | 
	  
      
	    Re: Can anyone help with that? ondata=customfunc
        
        Can you post the html source for the result page that you are getting. please? 
	   | 
	  
    
	
      | 
	    
         By: Manos 
        Date: 2009-09-07 
        Time: 19:11 
		
	   | 
	  
      
	    Re: Can anyone help with that? ondata=customfunc
        
        This is what i get: 
<ul> 
  <li><a href="showColors.php?colId=1"></a></li> 
  <li><a href="showColors.php?colId=2"></a></li> 
  <li><a href="showColors.php?colId=3"></a></li> 
  <li><a href="showColors.php?colId=4"></a></li> 
</ul> 
 |  
  
Each of the lines should have been like this:
 
<li><a href="showColors.php?colId=1">blue</a></li> 
... 
 |  
  
Inside the custom function if i change the code from this:
 
$CurrRec['color_name'] = $test[$CurrRec['id']]; 
 |  
  
to this:
 
$CurrRec['color_name'] = $CurrRec['id']; 
 |  
  
it works as expected. I get this:
 
<ul> 
  <li><a href="showColors.php?colId=1">1</a></li> 
  <li><a href="showColors.php?colId=2">2</a></li> 
  <li><a href="showColors.php?colId=3">3</a></li> 
  <li><a href="showColors.php?colId=4">4</a></li> 
</ul> 
 |  
  
Can you suggest a way to solve this? I really thing i miss something simple here..  
	   | 
	  
    
	
      | 
	    
         By: TomH 
        Date: 2009-09-08 
        Time: 01:22 
		
	   | 
	  
      
	    Re: Can anyone help with that? ondata=customfunc
        
        Maybe just... 
function getColor($BlockName,&$CurrRec,$RecNum) { 
   global $test; 
   $CurrRec['color_name'] = $test[$CurrRec['id']]; 
} 
 |  
  
	   | 
	  
    
	
      | 
	    
         By: Manos 
        Date: 2009-09-08 
        Time: 07:38 
		
	   | 
	  
      
	    Re: Can anyone help with that? ondata=customfunc
        
        yep, it works! Thanks man. This is my first project using TBS, i totally agree with the title Tiny But Strong :) 
	   | 
	  
    
	
    
	
    
       | 
      
	    
		
         
		  Posting in progress. 
          Please wait...
		 
		
	   |