Home     Articles & Projects     Products & Web Services     Forum

Only show data from the last R

Hi I was wondering if anyone can help me, I need to be able to get information from my MYSQL database but only show the data that was added since the last status = R

for e.g.

ID   |  Amount | Status
1   |0.00      | R
2   |1.90      | 0
3   |1.40      | 0
4   |0.00      | R
5   |0.50      | 0

What I want it to show is 0.50

Hi Russell, Most efficient

Hi Russell,

Most efficient way would be a 2-stage approach here.

1) SELECT the highest ID where status = R

2) SELECT all rows where ID > than ID returned in step 1

For example:

$result = mysql_query("SELECT max(id) AS id FROM table WHERE status='R'");
$row = mysql_fetch_array($result);
$max = $row["id"];
$result = mysql_query("SELECT * FROM table WHERE id > ".$max);
...

Hope this helps!
Cheers,
David.

Thank you for that help,

Thank you for that help, came in handy when the user wants to reset their campaign.

I have another question along the same line.
When a user places money into their account whats the best way to show the balance of the users account
say the user has $1.08 in their account then they add $300.00 in their account what would be the best way to show 301.08

but also taking into count what the user has been spending?

If you would like a copy of the transaction database just ask, and ill paste a sample of it.

Hi Russell, Treat them

Hi Russell,

Treat them completely separately. After you have created the transaction to credit their account with $300.00, then show the account balance after that - just as you should be able to call up an account balance at any time - so it should include the $300.00 if your "getBalance" function is called after the credit transaction has taken place...