First Problem:
When user deleted particular row then i have to remove that row only with out page refresh.
Deleting row using ajax. How can i do this
Second Problem:
Actually i am calculating the when ever page hits from that day to previous 7 days.
But i want when page hits today i have to retrieve previous week
Means from sunday(20 Nov 2011) to saturday (20 Nov 2011)
When page hits on next monday so i have to retrieve this week records
Means from sunday(27 Nov 2011) to saturday (03 Dec 2011)
function authenticate(){
$.ajax({
type: "POST",
url: "authentication.php",
data: $("#login_form").serialize(),
success: function(msg){
if(msg==1){
$('#delete').html("success"); //if success message appear only i have to remove particular row
})
}else{
$('#delete').html("error");
}
},
error:function(msg){
alert(msg);
$('#delete').dialog("close");
}
});
}
<div style='display: none;' id='delete'></div>
<table border="1">
<tr>
<th>Title</th>
<th>Public Id</th>
<th>Pass</th>
<th></th>
</tr>
<?php
$select = $db->select ()
->from ( 'test', '*' )
->where ( 'user_id = ?', 1 )
->where ( 'test.created > DATE_SUB(CURDATE(), INTERVAL 7 DAY)' );
$tourDetails = $db->fetchAll ( $select );
$i = 0;
foreach ( $tourDetails as $row1 ) {
$i ++;
$title = $row1 ['title'];
$PublicId = $row1 ['public_id'];
if (($i % 2) == 0 ) {
$rowResponse = prepareRow ( true, $title, $PublicId);
echo $rowResponse;
} else {
$rowResponse = prepareRow ( false, $title, $PublicId);
echo $rowResponse;
}
}
function prepareRow($flag, $title, $PublicId) {
$rowResponse = "";
if ($flag) {
$rowResponse .= '<tr class="even">';
} else {
$rowResponse .= '<tr class="odd" >';
}
$rowResponse .= '
<td> ' . $title . ' </td>
<td> ' . $publicId . ' </td>
<td><p><a onclick=openDialog("'. $PublicId .'","delete") href="#" id="dialog_link">
Delete </a></p>
</td>';
return $rowResponse;
?>
</table>
You can use jQuery’s nth-child selector.
This will remove the second row, for example. Make sure your table has an ID or a class so that you select it more easily (not accidentally removing 2nd row of EVERY table on the page, in case you have more)…
EDIT
From what I see in your code, you could select the parent tr element from your onclick event and then either send it to the function as a new parameter (which you would remove it the ajax returns success) or remove it right away… or whatever you want.