views:

614

answers:

1

I am using prototype js with PHP and mysql for update the status of record enable to disable vice versa in a grid. For this i use Ajax.Request method of prototype. status is updating but status icon was not change.

I am using image for showing enable or disable record. if record is enable in a grid then you can see enable.png image in a row of perticular record. Then i am changing the status of a perticular record in a grid, then status image should be changed with disable.png image in a grid for perticular record. In back end status has been changed but according to the current status image is not changing. My code is:

Step 1.

    <?php
require("Connection.php");

$sql = "SELECT * from tbluser";

$result=mysql_query($sql);

?>
<html>
<head>
    <script src="prototype.js" type="text/javascript"></script>
    <script src="scriptaculous-js/src/scriptaculous.js" type="text/javascript"></script>
    <script src="scriptaculous-js/src/unittest.js" type="text/javascript"></script>
    <script language="javascript">
     function fnDeleteRecord(id)
     {
         new Ajax.Request('delete.php?action=Delete&id='+id,{method:'get'});
         $(id).remove();
     }

 function fnUpdateStatus(id,value)
 {
  //new Ajax.Request('delete.php?action=Update&id='+id+'&status='+value, {method:'get',frequency:5,decay:3, onCreate: Ajax.Responders.register({onCreate: fnShowProcess(), onComplete:fnHideProcess()}), onSuccess:fnUpdateRecord});
  new Ajax.Request('delete.php?action=Update&id='+id+'&status='+value, {method:'get'});

 }
 function fnShowProcess()
 {
  var i = 0;
  if(Ajax.activeRequestCount > 0)

  document.getElementById('a[i]').style.display = 'inline';
 }
 function fnHideProcess()
 {
  var i=0;
  if(Ajax.activeRequestCount <= 0)
   document.getElementById('a[i]').style.display='none';
 }
 function fnUpdateRecord()
 {
  new Ajax.Updater('userrecords', 'index.php', {method:'post'});
 }
</script>

<body>
<table id="userrecords" border="1" cellpadding="0" cellspacing="0" width="700">

<tr>

<th> User Name </th>

<th> Password </th>

<th> Address </th>

<th> Phone Number </th>

<th> Action </th>
<th> Status </th>
</tr>

<?php

while($row = mysql_fetch_array($result))

{

echo "<tr id='".$row[id]."'>";

echo "<td>".$row['user_name']."</td>";

echo "<td>".$row['pass']."</td>";

echo "<td>".$row['address']."</td>";

echo "<td>".$row['phone_no']."</td>";

echo "<td><img src='images/spinner.gif' id='a[$row[id]]' alt=icon border=0 /><a href='javascript:void(0);' onclick=fnDeleteRecord('".$row['id']."'); >Delete</a></td>";

if($row['status'] == 'enabled')
 echo "<td><img src='images/spinner.gif' id='a[$row[id]]' alt=icon border=0 style='display:none;' /><img src='images/enable.png' alt=icon border=0 onClick=fnUpdateStatus('".$row['id']."','disabled')  /></td>";
else if ($row['status'] == 'disabled')
 echo "<td><img src='images/spinner.gif' id='a[$row[id]]' alt=icon border=0 style='display:none;' /><img src='images/disable.png' alt=icon border=0 onClick=fnUpdateStatus('".$row['id']."','enabled') /></td>";

echo "</tr>";

}

echo "</table>";

mysql_close($con);

?>

Step 2.

<?php
require_once('connection.php');

if ($_GET['action'])
{
    switch($_GET['action'])
    {
     case 'Delete':
      $sql = "Delete from tbluser where id ='".$_GET['id']."'";
      $result = mysql_query($sql);
      if(!$result)
       echo "some problem occured during delete operation";
      break;

     case 'Update':
      echo $sql = "UPDATE tbluser SET status = '".$_GET['status']."' WHERE id = '".$_GET['id']."'";
      $result = mysql_query($sql);
      if(!$result)
       echo 'some problem occured on server during update operation';
      break;
    }
}
?>
A: 

If you mean the database info is updating but the response is not, then you may be affected by a bug in firefox 3.5beta4 (firebug and other extensions that listen to ajax requests are inadvertently interfering with their reception by the page calling them.

If that's not what's happening here, could you be a little more specific about the problem?

Also the formatting seems to have been a little off so I'm not sure I have the whole picture of what you were trying to say.

Jonathan Fingland