jel
-
Posts
4 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by jel
-
-
PHP and AJAX
in PHP
That line of code will send the count of rows returned by the sql to the client. btw - it does work.I saved it to a file to check the accuracy of the synrtax.ThanksOkI think it's this line that messdes it up (I also don't get what it's doing there):echo "<table><tr><th>Count:</th></tr><tr><td>" . $num . "</td></tr></table>";
Remove it from the PHP and try again.Just curius: Why do you save it to a file?
-
PHP and AJAX
in PHP
here is the java script:var xmlHttpfunction showUser(str){ xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="getData.php" url=url+"?q="+str url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null)}function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { //document.getElementById("txtHint").innerHTML=xmlHttp.responseText; xmlDoc = xmlHttp.responseXML; document.getElementById('itemnumber').innerHTML= xmlDoc.getElementsByTagName('itemnumber')[0].childNodes[0].nodeValue; document.getElementById('itemcat').innerHTML= xmlDoc.getElementsByTagName('itemcat')[0].childNodes[0].nodeValue; document.getElementById('itemdesc').innerHTML= xmlDoc.getElementsByTagName('itemdesc')[0].childNodes[0].nodeValue; } }function GetXmlHttpObject() { var objXMLHttp=null if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest() } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") } return objXMLHttp }here is the php code:<?php$q=$_GET["q"];$con = mysql_connect('localhost', 'usrname', 'pwd');if (!$con) { die('Could not connect: '.mysql_error()); }mysql_select_db("myDB", $con);$sql="SELECT itemnumber, itemcat, itemdescFROM item_dataWHERE itemnumber = " . $q;$result = mysql_query($sql);$num = mysql_num_rows($result);if ($num!=0) {echo "<table><tr><th>Count:</th></tr><tr><td>" . $num . "</td></tr></table>";$file= fopen("results.xml", "w") or exit("Unable to open file!");$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";$_xml .="<item>\r\n";while($row = mysql_fetch_array($result)) { $_xml .= "\t<itemnumber>" . $row['itemnumber'] . "</itemnumber>\r\n"; $_xml .= "\t<itemcat>" . $row['itemcat'] . "</itemcat>\r\n";; $_xml .= "\t<itemdesc>" . $row['itemdesc'] . "</itemdesc>\r\n"; }$_xml .= "</item>";echo $_xml;fwrite($file, $_xml);fclose($file);mysql_close($con); } else { echo "No Records found"; } ?>
-
PHP and AJAX
in PHP
Hello, I am new to PHP and Ajax. I was trying to execute the 'PHP and AJAX responseXML Example' from the website.However, no matter what I have tried, I cannot get the XML data to display in the browser. I can display data through the responseText object but not the reponseXML object.It appears to be null once the XML object gets to the javascript. I have been able to create an XML document in the root directory of my server from the PHP code.I am running APACHE 2.2.4 and PHP 5.2.1 on a windows 2000 system using Firefox 1.5 and IE 6.0.2.This has been very frustrating for me!Any suggestions would be greatly appreciated!!
PHP and AJAX
in PHP
Posted