This topic is locked
[SOLVED]

 Updating a value on List View HELP

4/26/2011 2:42:41 PM
PHPRunner General questions
cyberjas2001 author

I have this formula to calculate the amount of days a truck has spent on my yard in my "List Page: After Record Processed" event



if ($data["DateOut"] == null) {

$starttime=strtotime($data["DateIn"]);

$endtime=strtotime(now());

$timediff = $endtime-$starttime;

$days=intval($timediff/86400);

$remain=$timediff%86400;

$hours=intval($remain/3600);

$remain=$remain%3600;

$mins=intval($remain/60);

$secs=$remain%60;
//$days is what you need

$data["DaysYard"] = $days; <<------------ This part doesn't seems to update my record

echo "DaysYard: " .$days; <<------------ I used "echo" to see the results i'm getting, and they are ok

}

else

echo "Done";
// this is just an output that tells the difrence

$timediff=$days.'days'.$hours.'hr'.$mins.'min'.$secs.'s';


The calculation goes ok, but it doesn't update the value of DaysYard. I know is something simple but I can't find the reason is not working.

Any ideas... thanks!

P
procheck 4/26/2011

For the List page, you need to use SQL (UPDATE or INSERT ...) to do this.

The $data value is only updated automatically in the edit event.

Sergey Kornilov admin 4/26/2011

If you want to update the value of $data["DaysYard"] move your code to List page: Before record processed event.

cyberjas2001 author 4/26/2011



For the List page, you need to use SQL (UPDATE or INSERT ...) to do this.

The $data value is only updated automatically in the edit event.


So in that case, how can I update my records???

cyberjas2001 author 4/26/2011



If you want to update the value of $data["DaysYard"] move your code to List page: Before record processed event.


Great!!! It just works!!! Thanks!!!.... now how can I use this calculation to update my SQL field "DaysYard"???

P
procheck 4/26/2011

It looks like I've learned something here too. I didn't think that these fields were updatable in List mode.

Great to know.

Sergey Kornilov admin 4/26/2011



It looks like I've learned something here too. I didn't think that these fields were updatable in List mode.

Great to know.


Just to clarify - it won't affect the real data in the database, just the copy of data to be displayed.

P
procheck 4/26/2011

Ok makes sense. I had misinterpreted the question. I thought that he wanted his table updated. Thanks for the clarification.

cyberjas2001 author 4/26/2011



Just to clarify - it won't affect the real data in the database, just the copy of data to be displayed.


Yes thats correct. But in my case besides of displaying my calculation on this field. Can I use it to update my SQL table?

cyberjas2001 author 4/26/2011



It looks like I've learned something here too. I didn't think that these fields were updatable in List mode.

Great to know.


Yes thats exactly what I want now

Sergey Kornilov admin 4/27/2011

prochecksports answered this question already:

For the List page, you need to use SQL (UPDATE or INSERT ...) to do this.


If SQL is not your forte use DAL:

http://xlinesoft.com/phprunner/docs/update.htm
The question you need to ask yourself - do you really want to update that many records in your database on each list page load?

cyberjas2001 author 4/27/2011



prochecksports answered this question already:
If SQL is not your forte use DAL:

http://xlinesoft.com/phprunner/docs/update.htm
The question you need to ask yourself - do you really want to update that many records in your database on each list page load?


And the answer is no, I take your advice, which is right, just for showing is ok but for updating will create a huge delay.

So in this case, can I add the same code on "edit page"?, so i will just update 1 record at the time it loads, the question is that I dunno which event can I use, any idea?