Hi
Im currently trying to learn javascript and have used the following code followed by a second file containing a php script. The idea of this script is as follows - the php script pulls in a number of results from a database. I then would like the java script to help display only one comment at a time. As you will be able to see there is a next button which when pressed I would like it to go to the next comment. How can I ask the java script to find the next 'commentid' in the results and display the contents??
Regards
Andy
Code 1
Code 2
Im currently trying to learn javascript and have used the following code followed by a second file containing a php script. The idea of this script is as follows - the php script pulls in a number of results from a database. I then would like the java script to help display only one comment at a time. As you will be able to see there is a next button which when pressed I would like it to go to the next comment. How can I ask the java script to find the next 'commentid' in the results and display the contents??
Regards
Andy
Code 1
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<script language="javascript" type="text/javascript">
function getPage(page){
var xmlhttp=false; //Clear our fetching variable
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
var file = 'text1.php?page='; //This is the path to the file we just finished making *
xmlhttp.open('GET', file + page, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
var content = xmlhttp.responseText; //The content data which has been retrieved ***
if( content ){ //Make sure there is something in the content variable
document.getElementById('content').innerHTML = content + "<br><br><font color=\"#CCCCCC\" size=\"1\" ><a href=\"[URL unfurl="true"]http://www.test.com\">PoweredBy</a></font>";[/URL] //Change the inner content of your div to the newly retrieved content ****
}
}
}
xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}
</script>
</head>
<body onload="getPage('157')">
<div id="content">
</div>
<div id="links" align="left">
<font size="1"><a href="javascript:getPage()">Next-></a></font>
</div>
</body>
</html>
Code 2
Code:
<?
require_once ('../../../templates/mysql_connect.php');
$page = $_GET["page"]; //This is the variable we retrieve through GET to know which row of content to retrieve
$sql = "SELECT commentsummary FROM comments where companyID = $page and rss = 1";
$query = mysql_query($sql) or die(mysql_error());
$r=mysql_fetch_assoc($query); //Set a mysql fetching variable for the query
echo $r["commentsummary"]; //Echo out the content of the page we want
?>