please get idea about my code...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hello all!
i wrote this code for parsing xml string that refer to attrs of 
teble.
but in it, array col cant be filled.
do u know why?
please get ur idea about this!
i will be happy, if u tell me : what is my error.
thanks

//////////////////
<?php

include_once"fetch_rec.php";/*in this file, i open db and connect to 
it, not more*/

class xmlParser{

///variable defination//////
	var $i=-1;
	var $strXml="";
	var $rows=0;
	var $col= array();/*for learn more about this method, please 
see:http://lists.evolt.org/archive/Week-of-Mon-20030324/138128.html*/
	var $saveTag=0;
	var $rTL=0;


/////handlers////////

	function startElement($strXml, $name, $attrs) {
		switch($name){
			case "TABLEDEF":
				if (is_array($attrs)) { 
					if ($attrs["DIV"]=="rtl"){
						$rTL=1;
					}
					if ($attrs["ROW"]=="true"){
						$rows=1;
					}
				}
				break;
			case "COL":
				$this->saveTag=1;
				break;		
			case "TITLES":
				$this->saveTag=2;
				break;		
			case "FIELDNAME":
				$this->saveTag=3;
				break;
		}
	}
	
	function endElement($strXml, $name) {
			
		
	}
	
	function characterData($strXml, $data){
		switch($this->saveTag){

			case 1:
				$this->i++;
				break;
			case 2:
				$col[$this->i]['fieldName'] =$data;

				break;
			case 3:
				$col[$this->i]['titles'] =$data;
				break;
		}
	}


////////////////////////////////////////////constructor//////////////
/////////////////////////////////////////

	function xmlParser($strXml){
		$xml_parser = xml_parser_create();
		xml_parser_set_option($xml_parser, 
XML_OPTION_CASE_FOLDING, true);
		xml_set_element_handler
($xml_parser, "startElement", "endElement");
		xml_set_character_data_handler
($xml_parser, "characterData");


	}

}//********end of class******


function createTable($strInput,$db_name){

	$xml_parser =new xmlParser($strInput);	
	$str.="<tr>";
	for($m=0; $m<=($xml_parser->i); $m++){	
		$str.="<td>".$col[$m]
['titles']."<td>";/////////////////fill titles of table/////
	}
	$str.="</tr>";

	for($m=0; $m<=($xml_parser->i); $m++){	
		$recCol=$col[$m]
['fieldnames']." , ";/////////////////product field names///////////
	}	

	$link=openDB($db_name);//////////////open table and set 
query//
	$rec="SELECT ".$recCol. "FROM ".$db_name;
	$result=mysql_query($rec);
	
	while($rec=mysql_fetch_row($result)){ /////////in this part  
fill str with rows of table/////////
		$str.='<tr>';
		for($i=0;$rec;$i++){
			$str.= '<td>'.$rec[$i].'</td>';
		}
		$str.='</tr>';
	}


	closeDB($link);//////////////error handling and close 
connection//////////
	//if (!xml_parse($xml_parser, $data, "TRUE")) {
	//	die("Parser Error");
	//}
	xml_parser_free($xml_parser1);

}
//**********end of createTable******

/*in main: 
echo '<table border=\"1\">';

createTable("<TABLEDEF DIV=\"rtl\" ROW=TRUE><COL><TITLES>عÙ?Ù?اÙ? خبر
</TITLES><FIELDNAME>titr</FIELDNAME></COL><COL><TITLES>تارÙ?Ø® خبر
</TITLES><FIELDNAME>date</FIELDNAME></COL><COL><TITLES>Ù?شرÙ?Ø­ خبر
</TITLES><FIELDNAME>description 
</FIELDNAME></COL></TABLEDEF>","news");

echo'</table>';
*/








PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux