View Single Post
Old 02-23-2013, 02:41 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
In your html file this line
Code:
xmlhttp.open("GET","2.php?q=",true);
is not sending anything as q... So your php query looks like this
PHP Code:
SELECT FROM step1 WHERE id '' 
.
Fix that first.

Then in your loop
Code:
for(i=1; i<="2.php?q="; i++)
is totally meaningless.

The number of rows sent back by the php is only being written into a div with an id of myDiv. I think you want that number in the loop commands.

Take this line out
Code:
<body onload="fone()">
and use it instead of the <body> tag you have. Plus fix up your html.

If your php sent back 2, and you can force this by making your php file be:
PHP Code:
echo 2
And you use this html:
Code:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body onload="fone()">
<div id="myDiv">div</div>

<script>
function fone()
{
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
	document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
	myFunction(xmlhttp.responseText);
}
}
xmlhttp.open("GET","2.php?q=",true);
xmlhttp.send('');


}

function myFunction(y)
{
	for(i=1; i<=y; i++)
	{
		var btn=document.createElement("BUTTON");
		btn.id = "join_btn" + i;
		btn.onclick = function() {
			var getID = parseInt(this.id.split("join_btn")[1]);
			document.location.href = pages[getID-1];
		}
		var t=document.createTextNode("JOIN");
		document.body.appendChild(btn);
		btn.appendChild(t);
		document.body.appendChild(document.createElement("br"));
		document.body.appendChild(document.createElement("br"));
	}
}

</script>
</body>
</html>
Things should work. Then figure out what you want to send as q and try it again.

Last edited by sunfighter; 02-23-2013 at 03:02 PM..
sunfighter is online now   Reply With Quote
Users who have thanked sunfighter for this post:
kksandyrox (02-24-2013)