i made a referral system , and i want to make when the referral reach level 5 to give money to the user who referred him .
i have something like this :
$sql = mysql_query("SELECT * FROM `users_ref` WHERE userid='$user[id]'");
$row = mysql_fetch_assoc($sql)
if (get_refuser_level($row['userref'] > 4) {
$update = mysql_query("UPDATE users SET money=money+$newmoney WHERE id='$user[id]'");
}
but if i made like this , i recive money every time wen i press F5 , it is possible to make this condition to run only one time or i need to make with db ?
The best approach would be to introduce a new boolean field storing whether the money is paid or not.
Related
I have a UserLog table that logs the actions "ADDED", "DELETED" or "UPDATED" along with the date/timestamp.
In Power BI, I would like to accurately show the amount of new users as well as removed users for a filtered time period. Since it's possible that a user has been added and then deleted, I need to make sure that I only get the last record (ADDED/DELETED) from the log for every user.
Firstly, I tried setting up a measure that gets the max date/timestamp:
LastUpdate = CALCULATE(MAX(UserLog[LogDate]), UserLog[Action] <> "UPDATED")
I then tried to create the measure that shows the amount of new users:
AddedCount = CALCULATE(COUNT(UserLog[userId]), FILTER(UserLog, [Action] = "ADDED" && [LogDate] = [LastUpdate]))
But the result is not accurate as it still counts all "ADDED" records regardless if it's the last record or not.
I find writing formulas against unstructured data is much harder. If you put a little more structure to the data, it becomes much easier. There are lots of ways to do this. Here's one.
Add 2 columns to your UserLog table to help count adds and deletes:
Add = IF([Action]="ADDED",1,0)
Delete = IF([Action]="DELETED",1,0)
Then create a summary table so you can tell if the same user was added and deleted in the same [LogDate]:
Counts = SUMMARIZE('UserLog',
[LogDate],
[userId],
"Add",SUM('UserLog'[Add]),
"Delete",SUM('UserLog'[Delete]))
Then the measures are simple to write. For the AddedCount, just filter the rows where [Delete]=0, and for DeletedCount, just filter the rows were [Add]=0:
AddedCount = CALCULATE(SUM(Counts[Add]),
Counts[Delete]=0,
FILTER(Counts,Counts[LogDate]=[LastUpdate]))
DeletedCount = CALCULATE(SUM(Counts[Delete]),
Counts[Add]=0,
FILTER(Counts,Counts[LogDate]=[LastUpdate]))
I need to calculate the time spent from one stop to another.
If the trip takes place in the same zipcode area and greater than one hour, I should report it.
For example,
The attached image with the dataframe shows the instance when arrivedTime from one stop to other in same zipcode has difference greater than one hour. I signal it. If it is less than one hour, no action needed. It should be grouped by and order by RuteID, Sequence and arrivedTime. In the attached example, the trip from zipCode 2300 to 2300 takes less then one hour it is ok. But If it is greater than one hour I should report by new column true/false for the number greater than one hour.
I would do this in power query using these steps:
Add a new column "NextSequence" = [Sequence]+1
Do a nested join with the table itsself, linking {"RoutID", "Sequence"} with {"RoutID", "NextSequence"} and when expanding, only keep the departedTime and ZipCode olumns calling them something like "prevDepTime" and "PrevZip"
write an IF-statement saying that if [PrevZip] <> null and [PrevZip] = [ZipCode] and [ArrivedTime]-[PrevDepTime] >= #time(1,0,0) then "Late" else "OK"
Clean up the table, keeping only the columns you want.
Then when loading the new table into power bi I have something that looks like this (I added a ew stops on RoutID2 for testing):
My M-code:
AddNextSequence = Table.AddColumn(PREVIOUS_STEP_NAME, "NextSequence", each [Sequence]+1, Int64.Type),
NestedJoin = Table.NestedJoin(AddNextSequence, {"RouteID", "Sequence"}, AddNextSequence, {"RouteID", "NextSequence"}, "AddedTable", JoinKind.LeftOuter),
ExpandTable = Table.ExpandTableColumn(NestedJoin, "AddedTable", {"DepartedTime", "ZipCode"}, {"PrevDepTime", "PrevZip"}),
Add_OkLate = Table.AddColumn(Expandedtable, "OK_or_Late", each if [PrevZip] <> null and [PrevZip] = [ZipCode] and Number.From([ArriveedTime]) - Number.From([PrevDepTime]) > Number.From(#time(1,0,0) ) then "Late"
else
"OK", type text),
FinalizeTable = Table.SelectColumns(AddOkLate,{"RowNumber", "RouteID", "Sequence", "ArriveedTime", "DepartedTime", "ZipCode", "OK_or_Late"})
in
FinalizeTable
I have found a very weird behaviour in our Siebel 7.8 application. This is part of a business service:
var bo:BusObject;
var bc:BusComp;
try {
bo = TheApplication().GetBusObject("Service Request");
bc = bo.GetBusComp("Action");
bc.InvokeMethod("SetAdminMode", "TRUE");
bc.SetViewMode(AllView);
bc.ClearToQuery();
bc.SetSearchSpec("Status", "='Unscheduled' OR ='Scheduled' OR ='02'");
bc.ExecuteQuery(ForwardOnly);
var isRecord = bc.FirstRecord();
while (isRecord) {
log("Processing activity '" + bc.GetFieldValue("Id") + "'");
bc.SetFieldValue("Status", "03");
bc.WriteRecord();
isRecord = bc.NextRecord();
}
} catch (e) {
log("Exception: " + e.message);
} finally {
bc = null;
bo = null;
}
In the log file, we get something like this:
Processing activity '1-23456'
Processing activity '1-56789'
Processing activity '1-ABCDE'
Processing activity '1-ABCDE'
Exception: The selected record has been modified by another user since it was retrieved.
Please continue. (SBL-DAT-00523)
So, basically, it processes a few records from the BC and then, apparently at random, it "gets stuck". It's like the NextRecord call isn't executed, and instead it processes the same record again.
If I remove the SetFieldValue and WriteRecord to avoid the SBL-DAT-00523 error, it still shows some activities twice (only twice) in the log file.
What could be causing this behaviour?
It looks like in business component "Action" you have join(s) that can return multiple records for one base record and you use ForwardOnly mode to query BC.
Assume, for example, in table S_EVT_ACT you have one record with a custom column X_PHONE_NUMBER = '12345678' and you have two records in table S_CONTACT with column 'MAIN_PH_NUM' equal to the same value '12345678'. So when you will join these two tables using SQL like this:
SELECT T1.* FROM SIEBEL.S_EVT_ACT T1, SIEBELS_CONTACT T2
WHERE T1.X_PHONE_NUMBER = T2.MAIN_PH_NUM
as a result you will get two records, with the same T1.ROW_ID.
Exactly the same situation happens when you use ForwardOnly cursor mode in eScript, in this case Siebel just fetches everything what database has returned. And that why it's a big mistake to iterate over business component while it's queried in a ForwardOnly mode. You should use ForwardBackward mode instead, because in this case Siebel will exclude duplicates records (it also true for normal UI queries, because it also executed in ForwardBackward mode).
Actually this is the most important and less known difference between ForwardOnly and ForwardBackward cursor modes.
Try changing that query mode
bc.ExecuteQuery(ForwardOnly);
to ForwardBackward.
Suppose each user on my site has a score which increases as they use the site (like Stackoverflow) and I have a field score stored in the user profile table for each user.
Getting the top 10 users of all time is easy, just order by the score column.
I want to have "top 10 today", "top 10 this week", "top 10 of all time".
What's the best way to implement this? Do I need to store every single score change with a timestamp?
You would have to have a table that stored the increments and use a timestamp. I.E.
CREATE TABLE ScoreIncreases (
PrimaryKey UNIQUEIDENTIFIER,
UserId UNIQUEIDENTIFIER,
ScoreIncrease INT,
CreatedDate DATETIME)
Your query would then be something like
SELECT TOP 1 u.PrimaryKey, SUM(ScoreIncrease)
FROM Users u
INNER JOIN ScoreIncreases si ON si.Userid=u.PrimaryKey
WHERE DATEDIFF(day,si.CreatedDate,GETDATE()) = 0
GROUP BY u.PrimaryKey
ORDER BY SUM(ScoreIncrease) DESC
I'm trying to figure out how to do a query with a where blah=blah or blah=blah2 with subsonic 3 linq and I can't figure it out. My query at the moment looks like this:
var ddFaxNumbers = from f in rf_faxnumber.All().Where(f => f.assigned == null).Where(f => f.location == currentFaxNumberRecordData.location)
select f;
This is a page with an update panel where when the user clicks edit I display 2 dropdowns, one for location, and one for the phone numbers. The current phone number is assigned, and marked so in the database table, so when I try to bind the dropdown it throws an error since the results don't contain the currently assigned number. I need to be able to query the table like so:
select * from numbers where assigned == null or number == currentnumber and location=selecteLocation. What I can't figure out in the SS syntax is how to do the OR part of the query. I don't see an .or, so is this even possible? Thanks for your help in advance.
Jon
You should be able to just do:
var ddFaxNumbers = from f in rf_faxnumber.All()
where (f.assigned == null || f.location == currentFaxNumberRecordData.location)
select f;