Jump to content

ajax php and mysql


adzie

Recommended Posts

Hello guys,

 

My script currently finds all users from my DB, once its done this i'd like to be able to click a button and more information appear below that users number and name.

 

First it searchs and for each result shows a row containing the number and name and a click box.

 

When I click the box it should show the details script, but currently no matter which row I click it always shows the details for the very first rows number and always displays this below the first user.

 

any thoughts, ideas, suggestions?

 

many thanks

 

 

 

print "<tr>
print "<td>$num</td>";
print "<td>$name<td>";               
print "<td>
<form>
<input type=text id=num value='$num'>
<input type=button onclick=ajaxFunction() value=Query MySQL />
</form>
</td>";
print "<td>";
print "<div id=ajaxDiv>Your result will display here</div>";
print "</tr>";

 

 

<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
function ajaxFunction(){
var ajaxRequest;  // The variable that makes Ajax possible!

try{
	// Opera 8.0+, Firefox, Safari
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	// Internet Explorer Browsers
	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			// Something went wrong
			alert("Your browser broke!");
			return false;
		}
	}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
	if(ajaxRequest.readyState == 4){
		var ajaxDisplay = document.getElementById('ajaxDiv');
		ajaxDisplay.innerHTML = ajaxRequest.responseText;
	}
}
var pilot_num = document.getElementById(num').value;
var queryString = "?num=" + num;
ajaxRequest.open("GET", "details.php" + queryString, true);
ajaxRequest.send(null); 



}

//-->
</script>

Link to comment
Share on other sites

It's hard to tell with what you posted..

 

You could send all the details from the get go, making that part hidden with a toggle link to show/hide it, per user.

 

Otherwise, we'd probably need to see the php loop that's display all the data for the users being queried.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.