inserting, updating, fetching using ajax

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

inserting, updating, fetching using ajax

Post by shivam0101 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to insert/update and also retrive data using ajax.

This is the script in HTML file

[syntax="html"]

<html>
<head>
<script language="JavaScript">

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}



function GetCurrentOnline()
{
    xml_obj=GetXmlHttpObject();

	var url="../current_online.php";
	url=url+"?member_id="+96;
	xml_obj.onreadystatechange=OnlineChanged;
	xml_obj.open("GET",url,true);
	xml_obj.send(null);
}


function OnlineChanged() 
{ 
if (xml_obj.readyState==4 || xml_obj.readyState=="complete")
 { 
 document.getElementById("current_online").innerHTML=xml_obj.responseText; 
 } 
}




</script>
</head>


<body onLoad='GetCurrentOnline();'>
<div id='current_online'></div>


</body>

</html>


in the current_online.php file,[/syntax]

Code: Select all

$member_id=$_GET['member_id'];

$member_id=96;
$cls_obj=new Cls;


  
$cls_obj->InsertOrUpdateCurrentOnline($member_id);

$online_members=$cls_obj->GetCurrentOnline($member_id);

echo $online_members;

in Cls file

Code: Select all

function InsertOrUpdateCurrentOnline($memberId)
{
   $member_id=$memberId;
   $current_time=time();
   
   if($this->NumRows(array(online), "WHERE member_id=$member_id")>0)
     $update=$this->Update(array(online_time), array("'$current_time'"), 'online', "member_id=$member_id");
   else
     $insert=$this->Insert(array(member_id, online_time), array("'$member_id'", "'$current_time'"), 'online');
}


function GetCurrentOnline($memberId)
{
   $member_id=$memberId;
   $time_check=time()-10000;
   
   
   $current_members=$this->GetAllRows(array(), array(online), "WHERE member_id != $member_id AND online_time > $time_check");
  // print_r($current_members);
      $table.="<table><tr>";
   foreach($current_members as $member)
   {
      $table.="<td> $member[member_id] </td>";
   }
     return $table.="</tr></table>";
  
}
I am not getting the outputs


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

have you tried to open current_online.php in a separate browser window to make sure it is working correctly?
Post Reply