tags:

views:

37

answers:

1

i have a list of rows from my db with delete next to each row but ajax is always deleting the first row in the list no matter what.

PHP CODE >>>>>>

$allowedFunctions = array(
   'add_job',
   'get_log',
   'delete'
);

$functionName = $_GET[ 'func' ];

if( in_array( $functionName, $allowedFunctions ) && function_exists( $functionName ) )
{

    $functionName();
}  

PHP DISPLAY PAGE >>>>>>

function manage(){
     dbconnect();
            $qry="SELECT server,id,email,lstcheck,running,runtime,pid FROM adds";
    $result=mysql_query($qry);
          $i = 0;
    echo"<table id='customers'>
<tbody><tr>
<th>Server</th>
  <th>Id</th>
  <th>Email</th>
  <th>Check Date</th>
  <th>Delete</th>
</tr>"; 
while($row = mysql_fetch_array($result))
{
echo "
";
if($i%2 == 0)
{   
        $tr="<tr>";
        $i++; 
    } else { 
        $tr="<tr class='alt'>";
        $i++; 
    }
echo"$tr
  <td><input type='text' name='sip' id='sip' size='10' value='".$row['server']."' /></td>
  <td><input type='text' name='id' id='id' size='10' value='".$row['id']."'/></td>
  <td><input type='text' name='email' id='email' size='10'value='".$row['email']."' /></td>
 <td><input type='text' name='lstchk' id='lstchk' size='10'value='".$row['lstcheck']."' /></td>
<td><input type='submit' name='Submit' id='Submit' onClick=\"getAjaxInfom('delete')\" value='Remove' /></td>
</tr>";
    }
echo"</tbody></table><div id='resultm'></div>";
    }

DELETE FUNCTION>>>>>

    function delete() {
dbconnect();
$sip = $_GET[ 'sip' ];  
$id = $_GET[ 'id' ];  
$email = $_GET[ 'email' ];
$lstchk = $_GET[ 'lstchk' ];
$ok = $_GET[ 'ok' ];
mysql_query("delete from adds where id='$id'");

echo $sip .$id.$email;

}

AJAX CODE>>>>>>>>>

    function getAjaxInfom(f) { // submit buton function
    var myFunction= f;
    var sip = document.getElementById("sip").value;
    var id = document.getElementById("id").value;
    var email = document.getElementById("email").value;
    var lstchk = document.getElementById("lstchk").value;
    var url = "includes/func.php?func=" + myFunction + "&sip=" + sip  +"&id=" + id +"&email=" + email +"&lstchk=" + lstchk +"";
 request.open("GET", url, true);
 request.onreadystatechange = updatePage1;
 request.send(null);
   }

  function updatePage1() {
     if (request.readyState == 4) {
       if (request.status == 200) {
         var response = request.responseText;
             document.getElementById("resultm").innerHTML = response; //responce for submit
               } else
         alert("status is " + request.status);
     }
   }

need some help on this

A: 

it looks like the input fields in every row getting the same id's - wich is a very bad idea. try to make the id's being unique and it should work well. maybe you can add the $i-value to every id like id='id_".$i."', put the $i-value as second argument into your getAjaxInfom-call (onClick=\"getAjaxInfom('delete','".$i."')\") and edit getAjaxInfom to do something like var sip = document.getElementById("sip:"+SECOUND_ARGUMENT).value; (and with the other values, too)

oezi
Thanks oezithe input fields do get unique id's becouse they are a result of an mysql query but what you have surgested will work for me becouse i can use (onClick=\"getAjaxInfom('delete','".$i."')\") and var sip = document.getElementById("sip:"+SECOUND_ARGUMENT).value; to pass to my delete function this will inturn give the correct id value i wish to deleteThanks Again
Alex