Page 1 of 1

call to undefined function problem

Posted: Mon Aug 01, 2005 7:32 am
by mmc01ms
hi guys scripts below i keep getting this error.

Code: Select all

Fatal error: Call to undefined function: db_result_to_array() in /home/sites/manpreetsandhu.com/public_html/xslt.class.php on line 35
however the function is in the class?

Code: Select all

<?php
	
	include_once ('common_db.php');
	
	
	class xslt 
	{
		var $xslfile;
		var $xmlfile;
		var $filename;
		
		//xslt gets the xml and xsl files to perform the transformation
		
		function db_result_to_array($result)   
			
		{
			$res_array = array();
			for ($count=0; $row = @mysql_fetch_array($result); $count++)  
				$res_array[$count] = $row;                
			return $res_array;   
		}
		
		function get_artist()
		{
			$link_id = db_connect();
			$query = "select artist_id from vinyls";
			$result = @mysql_query($query, $link_id);
			var_export($result);
			if (!$result)
				return false;
			$num = @mysql_num_rows($result);
			if($num == 0)
				return false;
			
			$result = db_result_to_array($result);
			return $result;
		}
		
		function write_xml()
		{
			
			$this->array_type = $this->get_artist();
			var_export($this->array_type);
			
			$this->handle = fopen("../xml/dynamic-phpbuilder.xml","w");
			
			$this->tofile = "<" . "?" . "xml version=\"1.0\"" . "?" . ">\n";
			$this->tofile .= "<" . "?" . "xml-stylesheet href=\"dynamic-phpbuilder.xsl\" type=\"text/xsl\"" . "?" . ">\n";
			$this->tofile .= "<" . "?" . "cocoon-process type=\"xslt\"" . "?" . ">\n\n";
			$this->tofile .= "<root>\n";
			$this->tofile .= "\t<literal-element>This is a Dynamically Generated XML that has been Transformed using XSLT</literal-element>\n";
			
			
			for ($x=0;$x<sizeof($this->array_type);$x++) 
			{
				$this->tofile .= "\t<vinyls>\n";
				$this->tofile .= "\t\t<artist_id>" . $this->array_type[$x] . "</artist_id>\n";
				$this->tofile .= "\t</vinyls>\n";
			}
			
			$this->ofile .= "</root>\n";
			
			
			fwrite($this->handle,$this->tofile);
			fclose($this->handle);
		}
		
		
		function xslt($xslfile= '', $xmlfile= '')
		{
			$this->xsl_string = "../xsl/".$xslfile;
			$this->xml_string = "../xml/".$xmlfile;
		}
		
		function transform()
		{
			$this->result = '';
			
			$xslHandle = xslt_create(); //create the processor 
			
			//pass the xslt_process function the files
			$this->result = xslt_process($xslHandle, $this->xsl_string, $this->xml_string);
			
			if(!$this->result)
			{
				die("XSLT Error:" .xslt_error($xslHandle));
				
				xslt_free($xslHandle);
				
				return false; 
			}
			return $this->result;
			
		}
	}
	
?>

Posted: Mon Aug 01, 2005 7:38 am
by timvw
db_result_to_array is not a function, it's a method of the class xslt.

So if you call it in the other method get_artist, you should do it as:

Code: Select all

function get_artist()
{
   ...
   $this->db_result_to_array(..);
   ...
}
Btw, if you start refactoring, you'll probably discover that database retrieval has absolutely nothing to do with XSLT so it belongs in that class..