Login   Register  
PHP Classes
elePHPant
Icontem

File: create.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Anderson Manuel  >  Show any MySQL table  >  create.js  >  Download  
File: create.js
Role: Auxiliary data
Content type: text/plain
Description: read the xml and create a table
Class: Show any MySQL table
Retrieve data from a MySQL table into XML
Author: By
Last change: changes on url variable
Date: 2009-08-12 03:03
Size: 2,225 bytes
 

Contents

Class file image Download
// JavaScript Document created by Anderson Manuel
// andernany@gmail.com
 
  function ajax()
  {   
    	var URL = 'fill.php';
  	  var param = 'host=' +$('host').value;
  	  		param+='&user='+$('user').value;
     	    param+='&pass='+$('pass').value;
     	    param+='&table='+$('table').value;
     	    param+='&database='+$('database').value;
     
     	    
  	  var myajax = new Ajax.Request(URL,{method:'post',parameters:param, onComplete:fill_table});
  
  }
  
  
  function fill_table(request)//to read data from extenal xml and fill de table
  {
	  var xmldoc = request.responseXML;
	  var header = xmldoc.getElementsByTagName('heads')[0];
	  var table = Builder.node( 'table' , {width:'100%', cellspacing:'0', cellpadding:'2', border:'1'} ); 
	 
	  var col;
	 
	  if(header!=null)
	  {
	  	col = header.getElementsByTagName('cols');
	  	var thead = fill_header(col);
	  	var reg = xmldoc.getElementsByTagName('regs');
	    var tbody = fill_body(reg); //to fill the header colum header
	    	
	    table.appendChild(thead);
	    table.appendChild(tbody);
	   	
	  	$('test').appendChild(table);
	 		table=null;
	 
	 }
	 else{$('test').appendChild("Ops!!");}
  }
  
  function fill_header(cols)
  { 
  	var i;
  	var tbody = Builder.node('tbody');
  	tr = Builder.node('tr',{className:'header'});
  	
  	for( i=0; i<cols.length; i++)
  	{ 
			 td = Builder.node('td',[Builder.node('strong',cols[i].firstChild.data)]);
			 tr.appendChild(td);
		 }
		 tbody.appendChild(tr);
		 
	 return tbody;
  }
  
  function fill_body(reg)//fill the td in a table
  {
  	var tbody = Builder.node('tbody');
  	var i;
  	for( i=0; i<reg.length; i++)
  	{
  		var item = reg[i].getElementsByTagName('item');
  		tr = Builder.node('tr',{className:'body'});
  		for( j=0; j<item.length; j++ )
  		{
  			if(item[j].firstChild!=null)
  			 {
  			  	td = Builder.node('td',[Builder.node('normal',item[j].firstChild.data)]);
  			  	tr.appendChild(td);
  			 }
  			 else
  			 	{
  			 		td = Builder.node('td',[Builder.node('normal','')]);
			 			tr.appendChild(td);
  			 	}
  		}
  		tbody.appendChild(tr);
  		
  	}
  	return tbody;
  }