john6384
-
Posts
24 -
Joined
-
Last visited
Never
Posts posted by john6384
-
-
I think that it is to do with the order that my code executes i.e. element has not been populated or assigned anything before it is used - this gives an empty.
To solve this I tried to make the whole of the code shown a function that is called after another function is used to setup the page - point of this was to make element not empty.
This did not work - please suggest how I can debug this or any other ideas.
-
I am trying to set a parameter in my XSL to be a PHP variable that I know is working as it can be seen using an alert in the AJAX.
Element keeps coming through as empty - javascript error.
Any more code, explanation needed then please say.
Cheers
var username = '<?php echo $username;?>'; var myXMLHTTPRequest = new XMLHttpRequest(); var myXSLTProcessor = new XSLTProcessor(); alert(username); //load the XSL file myXMLHTTPRequest.open("GET", "mnu.xsl", false); myXMLHTTPRequest.send(null); //get the XML document xslStylesheet = myXMLHTTPRequest.responseXML; myXSLTProcessor.importStylesheet(xslStylesheet); //load the xml file myXMLHTTPRequest.open("GET", "mnu.xml", false); myXMLHTTPRequest.send(null); var xmlSource = myXMLHTTPRequest.responseXML; alert(myXMLHTTPRequest.responseText); myXSLTProcessor.setParameter(null, "username", username); fragment = myXSLTProcessor.transformToFragment(xmlSource, document); var element = document.getElementById("menuTarget"); while(element.firstChild) { element.removeChild(element.firstChild); } element.appendChild(fragment);
-
Well this function was given to me but I dont think its complete and also it gives back in the alert in the AJAX - query was empty.
function SQLFromXML($doc){ global $sqlString; //Initialize the XML parser $parser=xml_parser_create(); //Function to use at the start of an element function start($parser,$element_name,$element_attrs) { global $sqlString; $sqlString="insert into " . $element_name . "("; $seperator=""; foreach ($element_attrs as $key => $value) { $sqlString=$sqlString . $seperator . $key; $seperator=","; } $sqlString=$sqlString . ") values("; $seperator=""; foreach ($element_attrs as $key => $value) { $sqlString=$sqlString . $seperator . "'" . $value . "'"; $seperator=","; } $sqlString=$sqlString . ")"; } //Function to use at the end of an element function stop($parser,$element_name) { // echo "<br />"; } //Function to use when finding character data function char($parser,$data) { // echo $data; } //Specify element handler xml_set_element_handler($parser,"start","stop"); //Specify data handler xml_set_character_data_handler($parser,"char"); //parse data xml_parse($parser,$doc); //Free the XML parser xml_parser_free($parser); return $sqlString; }
Any comments on why this is returned in the alert?
Cheers
-
Hello, first of all I have some AJAX that POST's a PHP files output like so:
//XMLResults is a string of XML ... XMLResults += '/>'; var objHTTP, strResult; objHTTP=new XMLHttpRequest(); objHTTP.open('POST', "PutData.php", false); objHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); objHTTP.overrideMimeType('text/html'); objHTTP.send("xml=" + xmlDoc); strResult=objHTTP.responseText;
Now in PutData.php I need to convert from XML to SQL.
What is the best way of doing this?
I have this to get the data from the POST:
foreach($_POST as $key => $data){ mysql_query(SQLFromXML($data)) or die (mysql_error()); }
Then I will need a function to do the work - please describe the structure of this and give any hints or point me to code.
Thankyou
-
All I need is to know the appropriate function for the xsltProcessor.
-
I need to use xsltProcessor to set a variable to something.
What xsltProcessor function would I use - the below does not work?
var item = document.getElementById("descriptionInput"); xmlDoc = myXMLHTTPRequest.responseXML; var search = xsltProcessor.transformToFragment(xmlDoc, document); myDOM = search; document.getElementById("XMLDiv").innerHTML = search;
I want to make search an xsltprocessor variable with value of item.
Thank you
John
-
I made some progress in using XSL variables.
This code gives an error in IE - error: object expected line 6 char 1
http://127.0.0.1/buglist.xml?descriptionInput=ateststring
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:variable name="isPriority" select="2"></xsl:variable> <html> <head> <title></title> <script language="javascript"> <![CDATA[ var XSLStylesheet; var XSLTProcessor = new XSLTProcessor(); var xmlhttp = new XMLHttpRequest(); var XMLDOM; function descriptionSearchFunction(){ ID = document.getElementById("descriptionInput").innerHTML; alert("ID2"); if(window.ActiveXObject){ XMLDOM = new ActiveXObject('Msxml2.FreeThreadedDOMDocument'); XMLDOM.async = false; XMLDOM.loadXML("buglist.xml"); XSLTDOM = new ActiveXObject('Msxml2.FreeThreadedDOMDocument'); XSLTDOM.async = false; XSLTDOM.load("BugList.xsl"); XSLStylesheet = new ActiveXObject('Msxml2.XSLTemplate'); XSLStylesheet.stylesheet = XSLTDOM; XSLTProcessor = XSLStylesheet.createProcessor(); XSLTProcessor.input = XMLDOM; XSLTProcessor.addParameter('isPriority', ID); XSLTProcessor.transform(); } //If mozilla browser else if(window.XMLHttpRequest){ xmlhttp.onreadystatechange = state_Change xmlhttp.open("GET","buglist.xml",false) xmlhttp.send(null) } try{ content.innerHTML=XSLTProcessor.output; } catch(e){ document.open(); document.write(XSLTProcessor.output); document.close(); } } function state_Change() { // if xmlhttp shows "loaded" if (xmlhttp.readyState==4) { // if "OK" if (xmlhttp.status==200) { document.getElementById('XMLDiv').innerHTML = xmlhttp.responseText; } else { alert("Problem retrieving XML data"); } } } ]]> </script> </head> <body> <form name='descriptionSearchForm'> <input type='text' name='descriptionInput' id='descriptionInput' onsubmit='descriptionSearchFunction()'></input> </form> <div id="XMLDiv"> </div> <table id="buglist" style="border:1px solid black" height= "400" width="1000"> <tr><td>ID</td><td>Priority</td><td>Description</td></tr> <xsl:for-each select="buglist/bug"> <tr> <xsl:choose> <xsl:when test="IsPriority>=$isPriority"> <td><xsl:value-of select="ID"/></td> <td><xsl:value-of select="IsPriority"/></td> <td><xsl:value-of select="Description"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="ID"/></td> <td><xsl:value-of select="IsPriority"/></td> <td bgcolor="#ff00ff"><xsl:value-of select="Description"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Cheers anyone
-
Well im almost there when using IE but not in Firefox.
I understand the code that uses an activeXObject although I do not understand how to do this for XMLHTTPRequest.
Some clues please:
<script language="javascript"> <![CDATA[ var XSLStylesheet; var XSLTProcessor = new XSLTProcessor(); var XMLDOM; function descriptionSearchFunction(xmlfile,xslfile){ ID = document.getElementById("descriptionInput").innerHTML; if(window.ActiveXObject){ XMLDOM = new ActiveXObject('Msxml2.FreeThreadedDOMDocument'); XMLDOM.async = false; XMLDOM.loadXML(xmlfile); XSLTDOM = new ActiveXObject('Msxml2.FreeThreadedDOMDocument'); XSLTDOM.async = false; XSLTDOM.load(xslfile); XSLStylesheet = new ActiveXObject('Msxml2.XSLTemplate'); XSLStylesheet.stylesheet = XSLTDOM; XSLTProcessor = XSLStylesheet.createProcessor(); XSLTProcessor.input = XMLDOM; XSLTProcessor.addParameter('ID', ID); XSLTProcessor.transform(); }else if(window.XMLHttpRequest){ var myXMLHTTPRequest = new XMLHttpRequest(); myXMLHTTPRequest.open("GET", xslfile, false); myXMLHTTPRequest.send(null); var xslRef = myXMLHTTPRequest.responseXML; XSLTProcessor.importStylesheet(xslRef); xmlhttp.open("GET",xmlfile,true); xmlhttp.send(null); } try{ content.innerHTML=XSLTProcessor.output; } catch(e){ document.open(); document.write(XSLTProcessor.output); document.close(); } } ]]> </script>
Only clues as I do not learn when the code is written for me.
Cheers
-
Thanks for the reply.
I need to use xsltProcessor in order to make a variable in the XSL file that changes i.e:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <html> <head> <title></title> <script language="javascript"> <![CDATA[ var xslStylesheet; var xsltProcessor = new XSLTProcessor(); var myDOM; var xmlDoc; var ID = "1"; function descriptionSearchFunction(){ var myXMLHTTPRequest = new XMLHttpRequest(); myXMLHTTPRequest.open("GET", "BugList.xsl", false); myXMLHTTPRequest.send(null); xslStylesheet = myXMLHTTPRequest.responseXML; xsltProcessor.importStylesheet(xslStylesheet); myXMLHTTPRequest = new XMLHttpRequest(); myXMLHTTPRequest.open("GET", "buglist.xml", false); myXMLHTTPRequest.send(null); xmlDoc = myXMLHTTPRequest.responseXML; var fragment = xsltProcessor.transformToFragment(xmlDoc, document); ID = document.getElementById("descriptionInput").innerHTML; myXSLTProcessor.addParameter('ID', ID); myDOM = fragment; document.getElementById("descriptionInput").appendChild(fragment); } ]]> </script> </head> <body> <form name='descriptionSearchForm'> <input type='text' name='descriptionInput' id='descriptionInput' onkeyup='descriptionSearchFunction()'></input> </form> <table id="buglist"> <xsl:for-each select="buglist/bug"> <tr> <td><xsl:value-of select="if (ID != '') then ID > $ID else '5'"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Is the select if else statement correct? - is the syntax correct for checking if ID is nothing.
Also if you spot any other reason for this not working then please say.
Cheers
-
Hello, how would use a variable in an XSLT document that changes when a textfield is changed i.e I need an HTML field to filter the XML displayed by changing the XSLT.
So far I have the XML displayed and know how to change it using XSLT.
Also I have a Javascript function that detects a keypress in the HTML textfield.
Problem is how do I update XSLT with javascript or is this the wrong way.
The desired effect as you can guess is to have a search textfield that dynamically filters the XML.
Only want CLUES for this please and im using a forum as a last resort and becasue of lack of time.
Thank you
-
That did it - cheers mate.
Solved.
-
I am populating a drop down list from mysql DB using PHP.
Then javascript changes a tables content below according to the value selected.
Problem is I want it to have the last option chosen when the tables is loaded (refreshed).
Any more explantion then please say.
<script language="javascript" type="text/javascript" > function jumpto(formIn) { var form = formIn; form = form.users.options[form.users.options.selectedIndex].value; self.location='BugList.php?userName=' + form; } </script>
-
Could not update user on database:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`Initials`='MBs' `Pass`='michelle' `Email`='michelle@aol.com' WHERE `ID`=10' at line 1
Thats the error I get now.
Cheers for reply though.
-
I am trying to run this query although I get this error:
//Assign the query $query = "UPDATE webusers SET Name='$name' Initials='$initials' Pass='$password' Email='$email' WHERE ID=$ID"; //Execute query $result = mysql_query($query); if(!$result){ die("Could not update user on database: <br />".mysql_error()); }
Could not update user on database:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(ID=11 Name='Doug' Initials='DB' Pass='pass' Email='doug@aol.com') WHERE ID=11' at line 1
The syntax looks fine.
Please help and give reasons for this.
Cheers
-
Cheers for the reply. I will be using this idea for my website but not copying the code obviously.
-
Hello,
I am able to use variables in my css with the help of php.
Now what I need to do is get a form working on my page that changes the stylesheet so that the colour scheme of the page is changed.
This is the code for my style sheet (style.php):
<?php header("Content-type: text/css"); $colorIn = $_POST['color']; if($colorIn == "green") { $color = "green"; header("Location: index.php"); } else if($colorIn == "uberlord") { $color = "uberlord"; header("Location: index.php"); } echo <<<CSS /* --- start of css --- */ #contentLYR { position:absolute; width:705px; height:800px; z-index:1; border:thin solid 000000; left: 137px; top: 245px; background:$color; } #Border { position:absolute; width:680px; height:780px; z-index:1; left: 10px; top: 10px; background:$color; } ................ /* --- end of css --- */ CSS; ?>
And this is in my scheme changer page (index.php):
<form method="post" action="style.php"> <input type="radio" name="color" value="green" checked="checked">Green <br> <input type="radio" name="color" value="uberlord">Uberlord <br> <input type="submit" name="submit" value="Change" /> </form>
Please advise why this does not work.
Thanks anyone
-
Or does anybody know where i could find an example of table entry where there is the use of a foriegn and primary key??
Thanks
-
Ok thanks for that, I just needed to know where to look.
Im making the tables using mysql command line.
Here are my tables although im not sure if they will work - can you check if the foreign key and primary key are set right.
Once ive got the tables working ill be fine.
Please anyone check if these are right:
create table emp
(
EMPNO integer(4),
ENAME varchar(10),
JOB varchar(9),
MGR integer(4),
HIREDATE date,
SAL integer(7),
COMM integer(7),
DEPTNO integer(2),
FOREIGN KEY (EMPNO)
);
create table dept
(
DEPTNO integer(2) NOT NULL PRIMARY KEY,
DNAME char(14),
LOC char(13)
);
-
Hello, i have just downloaded mysql 5 in order to test some queries.
Can anybody please give me some idea or point me in the direction of where to research how to setup a mysql table with this.
Its mysql server 5 and ive been told that i can create tables with it. I just need a bit of info about this as im ok with queries but not actualy setting up databases.
Ive also got mysql admin and the query tool.
Thanks anyone
-
That helps, although when I use the mysql admin I get an error 1130 telling me I cannot connect to the database. Ill try a different hosting. Do only some hostings work - does anyone know any?
Thanks
-
I had a look on google but did not have much luck. I dont realy know what im looking for. Maybe you could give me a better idea of what im looking for. I just need to write a simple database and then do queries on it- i wish it was as simple as access.
cheers
-
Thanks is there not anything else that I can use - i dunno maybe i could upload something? I managed to make a table in phpmyadmin although its slow and i cannot figure out how to enter data into the table. I tried to get a free version of oracle (big file).
Cheers
-
Hello, I need to setup a simple sql database in order to test some queries out. What is the simplest way to set one up? I did try a free hosting package and using the phpmyadmin although that was very slow and crap. Is there any cool ways I can do this?
Thanks anyone
Set parameter in XSL using AJAX
in Javascript Help
Posted
Solved - put a function in main JS file that so that element is populated.