/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Ajax(return to the same page after edit)

Hi all,

Hope you are fine…..What I am trying to do it is suppose the user is in 2nd page so after the update the control will return to the 2nd page not in the first page.

Currently the control is returning to the first page after the update is done.I am using PHp,MySql,Ajax.The update is done successfully.Here is the code:

//index.php

[code=php]<?

$sql = “select * from `member`”;
$res=mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($res);
$m=3;
$page=intval($count/$m);
if(($count%$m)!=0)
{
$page=intval($count/$m)+1;
}
$p=1;
$n=($p-1)*$m;
$n1=$p*$m;
if($n1 > $count)
{
$n1=$count;
}
$n2=$n+1;
$sql = “select * from `member` limit $n,$m”;
$res=mysql_query($sql) or die(mysql_error());

?>
<script language=”javascript” src=”js/ajax.js”></script>
<script language=”javascript”>
function edit(member_id)
{
sendRequest(“backpack/backpack.php”,”mode=edit&member_id=”+member_id,”POST”);
}
function EditRecord(member_id)
{
var loginid = document.add_frm.loginid.value;
var mem_name = document.add_frm.mem_name.value;
var mem_email = document.add_frm.mem_email.value;
var mem_mobile = document.add_frm.mem_mobile.value;
document.getElementById(‘err’).innerHTML=””;
sendRequest(“backpack/backpack.php”,”mode=editrecord&loginid=”+loginid+”&mem_name=”+mem_name+”&mem_email=”+mem_email+”&mem_mobile=”+mem_mobile+”&member_id=”+member_id,”POST”);
}
function pagination(p)
{
sendRequest(“backpack/backpack.php”,”mode=pagination&p=”+p,”POST”);
}

</script>
</head>

<body>
<div id=”aa” style=”display:”>
<table width=”72%” border=”0″ align=”center” cellspacing=”1″>
<?
if($count>0)
{
while($row = mysql_fetch_array($res))
{
?>
<tr align=”center” valign=”middle” bgcolor=”#F4EDCE”>
<td height=”20″ bgcolor=”#E8E8E8″ class=”header_text6″>
<? echo $row[loginid];?>
</td>
<td bgcolor=”#E8E8E8″>
<? echo $row[name];?>
</td>
<td bgcolor=”#E8E8E8″>
<? echo $row[email];?>
</td>
<td bgcolor=”#E8E8E8″>
<? echo $row[mobile];?>
</td>
<td bgcolor=”#E8E8E8″><a href=”” class=”link2″ onClick=”edit(<?=$row[member_id]?>); return false;”>Edit</a></td>
<td bgcolor=”#E8E8E8″><a href=”” class=”link2″ onClick=”if(confirm(‘Are You Sure !’)) DeleteRecord(<?=$row[member_id]?>); return false;”>Delete</a></td>
</tr>
<?
}
}
else
{
?>
<tr bgcolor=”#FFFFFF”>
<td colspan=”6″ align=”center” class=”header_text6″>There is no record.</td>
</tr>
<?
}
?>
</table>

<table width=”72%” border=”0″ align=”center”>
<tr>
<td class=”listing”>Listing <?=$n2?>-<?=$n1?> of <?=$count?></td>
<td align=”right” class=”listing”>Total Pages:<?=$page?>
<?
if($p!=1)
{
$previous=$p-1;
?>
<a href=”#” onClick=”pagination(<?=$previous?>);return false;” class=”pagination”>Previous</a>
<?

}

for($i=1; $i<=$page; $i++)
{
if($i == $p)
{
?>
<a><?=$i?></a>
<?
}
else
{
?>
<a href=”#” onClick=”pagination(<?=$i?>);return false;” class=”pagination”><?=$i?></a>
<?
}
}

if($p!=$page)
{
$next_page=$p+1;
?>
<a href=”#” onClick=”pagination(<?=$next_page?>);return false;” class=”pagination”>Next</a>
<?
}
?>
</td>
</tr>
<tr>
<td height=”20″ align=”center” valign=”middle” colspan=”1″>
<font color=”#FF0000″><strong><div id=”err”></div></strong></font>
</td>
</tr>
</table>
</div>
<form name=”add_frm” method=”get”>
<div id=”add” style=”display:none”>
<table width=”72%” border=”1″ align=”center” cellpadding=”2″ cellspacing=”2″ bordercolor=”#FFFFFF” bgcolor=”#E8E8E8″ style=”border-collapse : collapse”>
<tr>
<td width=”42%” align=”right” class=”header_text3″>Member LoginID:</td>
<td width=”58%”><input name=”loginid” type=”text” class=”textfieldsm1″ id=”month2″></td>
</tr>
<tr>
<td width=”42%” align=”right” class=”header_text3″>Member Name:</td>
<td width=”58%”><input name=”mem_name” type=”text” class=”textfieldsm1″ id=”month2″></td>
</tr>
<tr>
<td align=”right” valign=”middle” class=”header_text3″>Member Email: </td>
<td><input name=”mem_email” type=”text” class=”textfieldsm1″ id=”login_id”></td>
</tr>
<tr>
<td align=”right” valign=”middle” class=”header_text3″>Mobile:</td>
<td><input name=”mem_mobile” type=”text” class=”textfieldsm1″ id=”month” onKeyPress=”if(event.keyCode >58 || event.keyCode <48) return false;”></td>
</tr>
<tr>
<td colspan=”2″ align=”center” valign=”middle”><input name=”image” type=”image” src=”images/submit.gif” width=”58″ height=”19″ onClick=”if(validation()) Add(); return false;”></td>
</tr>
</table>
</div>
</form>
[/code]

//backpack.php

[code=php]<?
// Back Page
require_once(“../includes/dbconnect.php”);
$loginid = $_POST[‘loginid’];
$mem_name = $_POST[‘mem_name’];
$mem_email = $_POST[‘mem_email’];
$mem_mobile = $_POST[‘mem_mobile’];
$member_id = $_POST[‘member_id’];
$mode = $_POST[‘mode’];
$p=$_POST[‘p’];

if($mode == “edit”)
{
$sql = “select * from `member` where `member_id`=’$member_id'”;
$res=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_array($res);
$str = ‘<table width=”72%” border=”1″ align=”center” cellpadding=”2″ cellspacing=”2″ bordercolor=”#FFFFFF” bgcolor=”#E8E8E8″ style=”border-collapse : collapse”>
<tr>
<td width=”42%” align=”right” class=”header_text3″>Member LoginID:</td>
<td width=”58%”><input name=”loginid” type=”text” class=”textfieldsm1″ id=”month2″ value=”‘.$row[loginid].'”></td>
</tr>
<tr>
<td width=”42%” align=”right” class=”header_text3″>Member Name:</td>
<td width=”58%”><input name=”mem_name” type=”text” class=”textfieldsm1″ id=”month2″ value=”‘.$row[name].'”></td>
</tr>
<tr>
<td align=”right” valign=”middle” class=”header_text3″>Member Email: </td>
<td><input name=”mem_email” type=”text” class=”textfieldsm1″ id=”login_id” value=”‘.$row[email].'”></td>
</tr>
<tr>
<td align=”right” valign=”middle” class=”header_text3″>Mobile:</td>
<td><input name=”mem_mobile” type=”text” class=”textfieldsm1″ id=”month” value=”‘.$row[mobile].'” onKeyPress=”if(event.keyCode >58 || event.keyCode <48) return false;”></td>
</tr>
<tr>
<td colspan=”2″ align=”center” valign=”middle”><input name=”image” type=”image” src=”images/edit.gif” width=”58″ height=”19″ onClick=”if(validation()) EditRecord(‘.$member_id.’); return false;”>&nbsp;&nbsp;<input type=”submit” name=”skip” value=”Skip” onclick=”skip(); return false;”></td>
</tr>
</table>^2′;
echo $str;
}

if($mode==”editrecord”)
{
$sql_edit=”update `member` set `loginid`=’$loginid’,`name`=’$mem_name’,`email`=’$mem_email’,`mobile`=’$mem_mobile’ where `member_id`=’$member_id'”;
mysql_query($sql_edit) or die(mysql_error());
$str = ‘<table width=”72%” border=”0″ align=”center” cellspacing=”1″>
<tr bgcolor=”#FC9694″>
<td width=”7%” align=”center” valign=”middle” bgcolor=”#B9B9B9″ class=”header_text3″>Member LoginID</td>
<td width=”6%” align=”center” valign=”middle” bgcolor=”#B9B9B9″ class=”header_text3″>Member Name</td>
<td width=”6%” align=”center” valign=”middle” bgcolor=”#B9B9B9″ class=”header_text3″>Member Email</td>
<td width=”6%” align=”center” valign=”middle” bgcolor=”#B9B9B9″ class=”header_text3″>Mobile</td>
<td width=”6%” align=”center” valign=”middle” bgcolor=”#B9B9B9″ class=”header_text3″>Edit</td>
<td width=”6%” align=”center” valign=”middle” bgcolor=”#B9B9B9″ class=”header_text3″>Delete</td>
</tr>’;

$sql = “select * from `member`”;
$res=mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($res);
$m=3;
$page=intval($count/$m);
if(($count%$m)!=0)
{
$page=intval($count/$m)+1;
}
$p=1;
$n=($p-1)*$m;
$n1=$p*$m;
if($n1 > $count)
{
$n1=$count;
}
$n2=$n+1;
$sql = “select * from `member` limit $n,$m”;
$res=mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_array($res))
{
$str.= ‘<tr align=”center” valign=”middle” bgcolor=”#F4EDCE”>
<td height=”20″ bgcolor=”#E8E8E8″ class=”header_text6″>’.$row[loginid].’
</td>
<td bgcolor=”#E8E8E8″>’.$row[name].’
</td>
<td bgcolor=”#E8E8E8″>’.$row[email].’
</td>
<td bgcolor=”#E8E8E8″>’.$row[mobile].’
</td>
<td bgcolor=”#E8E8E8″><a href=”” class=”link2″ onClick=”edit(‘.$row[member_id].’); return false;”>Edit</a></td>
<td bgcolor=”#E8E8E8″><a href=”” class=”link2″ onClick=”if(confirm(‘Are You Sure !’)) DeleteRecord(‘.$row[member_id].’); return false;”>Delete</a></td>
</tr>’;
}
$str.= ‘</table>’;
$str.='<table width=”72%” border=”0″ align=”center”>
<tr>
<td class=”listing”>Listing ‘.$n2.’-‘.$n1.’ of ‘.$count.'</td>
<td align=”right” class=”listing”>Total Pages:’.$page;
if($p!=1)
{
$previous=$p-1;
$str.='<a href=”#” onClick=”pagination(‘.$previous.’);return false;” class=”pagination”>Previous</a>’;
}
for($i=1; $i<=$page; $i++)
{
if($i == $p)
{
$str.='<a>’.$i.'</a>’;
}
else
{
$str.='<a href=”#” onClick=”pagination(‘.$i.’);return false;” class=”pagination”>’.$i.'</a>’;
}
}
if($p!=$page)
{
$next_page=$p+1;
$str.='<a href=”#” onClick=”pagination(‘.$next_page.’);return false;” class=”pagination”>Next</a>’;
}
$str.='</td>
</tr>
<tr>
<td height=”20″ align=”center” valign=”middle” colspan=”1″>
<font color=”#FF0000″><strong><div id=”err”></div></strong></font>
</td>
</tr>
</table>^3′;

echo $str;

}
?>[/code]

The problem is that everytime the $p is starting from 1.Could you please suggest me how can I do this to bring the control under same page where the update is done.

Thanks in advance for your earnest co-operation.

Regards,
Raj

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@raj_2006authorFeb 10.2008 — Hi All,

Its solved...basically have to send the value of $p frm one function to another function...thats it...its a 10 min work...and i took 1.5 days....:p

Regards,

Raj
×

Success!

Help @raj_2006 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.11,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...