This topic is locked
[SOLVED]

 ASP event to PHP

1/26/2010 2:40:50 PM
PHPRunner General questions
S
stealthwifi author

I have a Before Record Add event that performs a query then uses the result to fill in the "Number" field. It was made for ASP but I'm playing with PHP before we swtich and wanted to get this working first. Any idea how to convert?



Function BeforeAdd (values,message,inline)
set rstmp = Server.CreateObject("ADODB.Recordset")

rstmp.open "select max(Number)+1 from (Select max(Number) as Number from Allison union all Select max(Number) from AllisonArchive) t " ,dbConnection

dict("Number") = rstmp(0)

rstmp.close : set rstmp = nothing
BeforeAdd=true


Also I have a custom view on a list page to change the cell color to red any idea how to do this one in php?

str = "<table width=100% bgcolor="

if (DATEDIFF("yyyy", strValue, NOW()) > 3) then

str = str & "red"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str
S
stealthwifi author 1/28/2010



I have a Before Record Add event that performs a query then uses the result to fill in the "Number" field. It was made for ASP but I'm playing with PHP before we swtich and wanted to get this working first. Any idea how to convert?



Function BeforeAdd (values,message,inline)
set rstmp = Server.CreateObject("ADODB.Recordset")

rstmp.open "select max(Number)+1 from (Select max(Number) as Number from Allison union all Select max(Number) from AllisonArchive) t " ,dbConnection

dict("Number") = rstmp(0)

rstmp.close : set rstmp = nothing
BeforeAdd=true


Also I have a custom view on a list page to change the cell color to red any idea how to do this one in php?

str = "<table width=100% bgcolor="

if (DATEDIFF("yyyy", strValue, NOW()) > 3) then

str = str & "red"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str



Please anyone know how to do the first one?

All I need is before the record is added to perform the query and use the results as the value for Number field
I got the 2nd one for custom view using the below code:



global $data,$record;

if ($data["MSDS_Issue_Date"]<(DATE('Y')-3)&&$data["MSDS_Issue_Date"]!="null")

$record["MSDS_Issue_Date_style"]='style="background:red"';
J
Jane 1/28/2010

Here is just a sample:

global $conn;

$str = "...";

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);

$values["Number"] = $data[0];
S
stealthwifi author 1/28/2010

Thanks Jane that's perfect!
Also for anyone else I modified the Custom View to be as below:



global $data,$record;

if ($data["MSDS_Issue_Date"]<(DATE('Y')-3)&&$data["MSDS_Issue_Date"]!="null")

$record["MSDS_Issue_Date_style"]='style="background:red"';

$value = date( "m/d/Y", strtotime($value));


The reason being that last line, since the data type is SmallDateTime it shows the time part, and since i'm using custom view I can't set view as short so it doesn't show the time, the last line displays the datetime as just date (Month/Day/Year).
Change Y to y for 2 digit year and / to - or . for whatever format you like, theres more info about the PHP date function on the php site too.
Thought others might like that took me forever to figure it out <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=47261&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />