Jump to content

Recommended Posts

@anyone

 

I have installed a pagination page on my membership page to make a balance sheet in a way to see transaction details, I am currently working on a project to build an online bank project,  when I update mysql with a new data, I am expected to get a new row, but rather I see the old row has been re-written by the update of the mysql result.

How can I solve this problem  and below is my membership page.

------------------------------------------------------------------------------------------------------------------------------------------------

<?php
session_start();
include_once"config.php";
if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){
header("Location: login.php");
}else{
$fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE username='".$_SESSION['username']."'"));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>X-Bank Members Page</title>
</head>

<body>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
  <tr>
    <td width="33%">You are logged as <?php echo "".$fetch_users_data->username."";?></div></td>
    <td width="34%">Last IP Logged :</td>
    <td width="33%">Your Account Balance is : $ <?php echo "".$fetch_users_data->acctbal."";?></div></td>
  </tr>
</table>
<br />
<table width="100%" height="253" border="0" cellpadding="1" cellspacing="1">
  <tr valign="top">
    <td width="21%" height="205"><table width="100%" border="1" cellspacing="1" cellpadding="1">
      <tr>
        <td><div align="center"><a href="members.php" >Home</a></div></td>
      </tr>
    </table>
      <table width="100%" border="1" cellspacing="1" cellpadding="1">
        <tr>
          <td><div align="center"><a href="profile.php">Members Profile</a></div></td>
        </tr>
    </table>
      <table width="100%" border="1" cellspacing="1" cellpadding="1">
        <tr>
          <td><div align="center"><a href="changepass.php">Change Password</a></div></td>
        </tr>
    </table>
      <table width="100%" border="1" cellspacing="1" cellpadding="1">
        <tr>
          <td><div align="center"><a href="billpayment.php">Bill Payment</a></div></td>
        </tr>
    </table>
      <table width="100%" border="1" cellspacing="1" cellpadding="1">
        <tr>
          <td><div align="center"><a href="fundtransfer.php">Fund Tranfser</a></div></td>
        </tr>
    </table>
      <table width="100%" border="1" cellspacing="1" cellpadding="1">
        <tr>
          <td><div align="center"><a href="loans.php">Loans</a></div></td>
        </tr>
    </table>
      <table width="100%" border="1" cellspacing="1" cellpadding="1">
        <tr>
          <td><div align="center"><a href="logout.php">Logout</a></div></td>
        </tr>
    </table></td>
    <td width="79%" rowspan="2"><?php
    $page_name="members.php";
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start)){
echo "Data Error";
exit;
}
$eu = ($start -0);                
$limit = 2;                                 
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 
$query2=" SELECT * FROM members where username='".$_SESSION['username']."'";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);

$bgcolor="#f1f1f1";
echo "<TABLE width=90% align=center  cellpadding=0 cellspacing=0> <tr>";
echo "<td  bgcolor='dfdfdf' > Date</font></td>";

echo "<td  bgcolor='dfdfdf' > Transaction Type</font></td>";
echo "<td  bgcolor='dfdfdf' > Amount</font></td>";
echo "<td  bgcolor='dfdfdf' > Initial Balance</font></td>";
echo "<td  bgcolor='dfdfdf' > Charges</font></td>";
echo "<td  bgcolor='dfdfdf' > Final Balance </font></td>
</tr>";
$fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members`  WHERE username='".$_SESSION['username']."' limit $eu, $limit"));
echo mysql_error();
{
if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}

echo "<tr >";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->statementdate."</font></td>"; 
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->statementtrasct."</font></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->amounttransact."</font></td>"; 
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->intacctbal."</font></td>"; 
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->charges."</font></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->acctbal."</font></td>";
echo "</tr>";
}
echo "</table>";

$p_fwd=$p_f+$p_limit;
$p_back=$p_f-$p_limit;

echo "<table align = 'center' width='50%'><tr><td  align='left' width='20%'>";
if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV $p_limit</font></a>"; }
echo "</td><td  align='left' width='10%'>";
if($back >=0 and ($back >=$p_f)) { 
print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>"; 
}

echo "</td><td align=center width='30%'>";
for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit){
if($i <> $eu){
$i2=$i+$p_f;
echo " <a href='$page_name?start=$i&p_f=$p_f'><font face='Verdana' size='2'>$i</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$i</font>";}
}


echo "</td><td  align='right' width='10%'>";
if($this1 < $nume and $this1 <($p_f+$p_limit)) { 
print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT</font></a>";} 
echo "</td><td  align='right' width='20%'>";
if($p_fwd < $nume){
print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT $p_limit</font></a>"; 
}
echo "</td></tr></table>";
?>
</td>
  </tr>
  <tr valign="top">
    <td height="43"> </td>
  </tr>
</table>
<p> </p>
</body>
</html>

---------------------------------------------------------------------------------------------------------------------------------------------

will be glad if help will be rendered 

Link to comment
https://forums.phpfreaks.com/topic/240612-php-pagination/
Share on other sites

since you wish to display more than one row, you will need to place you mysql_fetch_object() function inside of a while loop. Also, I recommend puting your query into a variable before using it inside of the function

$result = mysql_query("SELECT * FROM `members`  WHERE username='".$_SESSION['username']."' limit $eu, $limit");
while($fetch_users_data = mysql_fetch_object($result))
{

if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}

echo "<tr >";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->statementdate."</font></td>"; 
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->statementtrasct."</font></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->amounttransact."</font></td>"; 
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->intacctbal."</font></td>"; 
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->charges."</font></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->acctbal."</font></td>";
echo "</tr>";
echo "</table>";
}

 

Edit: since "members" is not a mysql reserved word, you do not need to wrap it in backticks, however this is still acceptable

Link to comment
https://forums.phpfreaks.com/topic/240612-php-pagination/#findComment-1235865
Share on other sites

Thanks for the reply, I will heed to your advice but seems my problem is still not solved or maybe I am asking the wrong question .

here is error I am facing currently

 

If mysql database is updated  I expect a new row to be automatically formed but rather it will wipe the old data and replace it with the new one which is not what I want.

 

Thanks for your reply once again

Link to comment
https://forums.phpfreaks.com/topic/240612-php-pagination/#findComment-1235880
Share on other sites

placing the code in a while loop should fix the problem of only displaying one row, however I have realized an error that i made in the previous code, I placed the closing </table> tag inside of the while loop which I should not have done....try this instead.

$result = mysql_query("SELECT * FROM `members`  WHERE username='".$_SESSION['username']."' limit $eu, $limit");
while($fetch_users_data = mysql_fetch_object($result))
{

if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}

echo "<tr >";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->statementdate."</font></td>"; 
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->statementtrasct."</font></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->amounttransact."</font></td>"; 
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->intacctbal."</font></td>"; 
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->charges."</font></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>".$fetch_users_data->acctbal."</font></td>";
echo "</tr>"; //removed the </table> tag below
}

 

Link to comment
https://forums.phpfreaks.com/topic/240612-php-pagination/#findComment-1235884
Share on other sites

To be honest, I'm not entirely sure what your problem actually is.  Are you trying to add a new row to the database, and it's merely updating an existing row?  Are you trying to update an existing row, and it's creating a new row?  Is your pagination working correctly for existing entries?

Link to comment
https://forums.phpfreaks.com/topic/240612-php-pagination/#findComment-1235915
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.