Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This one uses post and is ready to go and change to your needs!</p> <p>html file (file name does not matter)</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var request = false; try { request = new XMLHttpRequest(); } catch (trymicrosoft) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { request = false; } } } if (!request) alert("Error initializing XMLHttpRequest!"); &lt;/script&gt; &lt;script type="text/javascript"&gt; var fileOption; function runPhp(Args) { var url = "script.php"; fileOption = Args; var params = "Args=" +Args+""; request.open("POST", url, true); //Some http headers must be set along with any POST request. request.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8"); request.setRequestHeader("Content-length", params.length); request.setRequestHeader("Connection", "close"); request.onreadystatechange = updatePage; request.send(params); }//////////////////// function getXml( ) { var url = 'temp.xml'; var params = null; request.open("POST", url, true); request.setRequestHeader("Connection", "close"); request.onreadystatechange = displayFile; request.send(params); }//////////////////// //You're looking for a status code of 200 which simply means okay. function updatePage() { if (request.readyState == 4) { if (request.status == 200) { if(fileOption==1) {fileName=request.responseText; return;} document.getElementById('divResults').innerHTML=request.responseText; document.getElementById('textareaResults').innerHTML=request.responseText; } else{ //alert("status is " + request.status); } } } function displayFile() { if (request.readyState == 4) { if (request.status == 200) { document.getElementById('textareaResults').innerHTML=request.responseText; document.getElementById('divResults').innerHTML='File loaded in text area above.'; } else{ //alert("status is " + request.status); } } } &lt;/script&gt; &lt;/head&gt; &lt;body &gt; &lt;span style="background-color:blue;color:yellow;" onClick="runPhp('GetFromMysql')"/&gt; Click this to get data from MySql.&lt;br&gt; &lt;/span&gt;&lt;br&gt;&lt;br&gt; &lt;span style="background-color:blue;color:yellow;" onClick="runPhp('MysqlToFile')"/&gt; Click this to get data from MySql and store them in a file instead of displaying.&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;/span&gt; &lt;span style="background-color:blue;color:yellow;" onClick="getXml()"/&gt; Click to read the xml file.&lt;br&gt; &lt;/span&gt; &lt;textarea rows="10" cols="88" id="textareaResults"&gt; &lt;/textarea&gt; &lt;br&gt;&lt;br&gt; &lt;pre&gt;&lt;div id="divResults"&gt;&lt;/div&gt;&lt;/pre&gt; &lt;br&gt;&lt;br&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and this is script.php</p> <pre><code>&lt;?PHP $xml_output = routine(); if($_POST['Args']==='GetFromMysql') echo $xml_output .= "&lt;/records&gt;"; elseif($_POST['Args']==='MysqlToFile') { $fileName = 'temp.xml'; $fp = fopen($fileName, 'w'); fwrite($fp, $xml_output); fclose($fp); echo "temp.xml";//return the file name } function routine() { mysql_connect('localhost', 'root',''); mysql_select_db("mysql"); $query="select * from help_category;"; $resultID = mysql_query($query ) or die("Data not found."); $xml_output = "&lt;?xml version=\"1.0\"?&gt;\n"; $xml_output .= "&lt;records&gt;\n"; for($x = 0 ; $x &lt; mysql_num_rows($resultID) ; $x++) { $row = mysql_fetch_assoc($resultID); $xml_output .= "\t&lt;record&gt;\n"; $xml_output .= "\t\t&lt;help_category_id&gt;" . $row['help_category_id'] . "&lt;/help_category_id&gt;\n"; $xml_output .= "\t\t&lt;name&gt;" . $row['name'] . "&lt;/name&gt;\n"; $xml_output .= "\t\t&lt;parent_category_id&gt;" . $row['parent_category_id'] . "&lt;/parent_category_id&gt;\n"; $xml_output .= "\t&lt;/record&gt;\n"; } return $xml_output; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload