This topic is locked

Turn Row Red upon Date?

8/10/2008 10:37:39 AM
PHPRunner General questions
S
swanside author

Hello
I have been trying to turn a whole row red if the Order_Date field is more than 30 days old, but I am not having much success.
I have tried this code

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

if Order_Date >now()+30{

$str.="red";

}

$str.="><tr><td>".$value."</td></tr></table>";

$value=$str;


Can somebody please help?
Thanks

Paul.

T
thesofa 8/10/2008

Hi

quite a few posts about date and time on here, try this reply of mine posted today that has links to 2 posts that may help.

sql and php deal with dates in a non logical way, I think they are stored as a unix timestamp so the number needs to be converted to a readable date.

HTH

S
swanside author 8/10/2008

Hi

quite a few posts about date and time on here, try this reply of mine posted today that has links to 2 posts that may help.

sql and php deal with dates in a non logical way, I think they are stored as a unix timestamp so the number needs to be converted to a readable date.

HTH


Thanks, I will have a look at them.
It not a timestamp, but a field that the user selects when a job is sent in by phone. Dont know if its much difference in the way it stores it?
Cheers

Paul.

T
thesofa 8/10/2008

I tried this

echo now();

echo "<p>";

echo (now()+2);


and I got this > Your message2008-08-10 16:12:13

2010



so it seems that now()+2 adds 2 years to the year date, but the rest of the date stamp goes.

Dunno, dig deeper.

S
swanside author 8/10/2008

Thats funny, that means my query is adding 30 years onto my database????
Cheers

T
thesofa 8/10/2008

thats what happened when I tried it, you have the code, just run it from a page!

S
swanside author 8/11/2008

Tried a few different things, but they dont seem to work, I either get one cell red and that dont change colour whayever I do, or, I get a big long PHP Error messege.

T
thesofa 8/11/2008

sorry, unable to help anymore out of my range, ask Jane or Alexy.

J
Jane 8/11/2008

Hi,
field value is stored in the $value variable or in the global $data array. Your Order_Date means nothing.

Also I recommend you to use PHP functions to compare dates:

http://php.net/manual/en/ref.datetime.php

S
swanside author 8/11/2008

Hi,

field value is stored in the $value variable or in the global $data array. Your Order_Date means nothing.

Also I recommend you to use PHP functions to compare dates:

http://php.net/manual/en/ref.datetime.php


No I am lost.
I think I need to google now! Its like a new language.

S
swanside author 8/11/2008



No I am lost.
I think I need to google now! Its like a new language.


OK I have a 10 hour Flight to Orlando in the next couple of weeks, WHat books does anybody recommend to try to help me with php and html coding?
Cheers

T
thesofa 8/11/2008

just have a good sleep!

S
swanside author 8/11/2008

just have a good sleep!


<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=32091&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />
Will do.

S
swanside author 8/11/2008

OK, been reading on varibles, seem to be getting abit of it now, but, how do I tell a variable that the information I want it to read is in a field called Order_Date?

Cheers
Update.
I tried this

$strFirst_Name = "David";

$strSpace = " ";

$strLast_Name = "John";

$strDate = "[`Order_Date`]";

$strName = $strFirst_Name.$strSpace.$strLast_Name.$strSpace.$strDate;
echo $strName;


It shows David John [`Order_Date`] when I run it?? and not the date?

T
thesofa 8/11/2008

assign a variable a value like this

first get the value of the field Order_Date.

this depends on where in the events you are doing it, because different parameters are used in different events. e.g. the beforeadd event for the add page has > function BeforeAdd(&$values,&$message,$inline)

// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair
{



so we would go

$strDate=$values["Order_Date"];



Note the syntax around the field name. By putting the double quotes around the variable name like you have, you have made PHP treat it as a literal expression, rather than using the value of the variable

that gets the value of the Order_Date field that you have filled in and puts it in the variable $strDate
Then we can build up the rest of the expression like this

$strFirst_Name = "David";

$strLast_Name = "John";

$strDate=$values["Order_Date"];

$strName = $strFirst_Name." ".$strLast_Name." ".$strDate;

Echo $strName;


I think that is right, give it a try.
If you do not have an array like $values available, you will have to do a lookup on the data to find the unique record, so find the primary key fore the record you just saved, make a search string using the primary key and get the result into an array, then reference the array like this

global $conn, $strTableName;
$str1 = "select * from `nd_staff` where `pcs_ac`='".$_SESSION["UserID"]."'";

$rs1 = db_query($str1,$conn);

$data1 = db_fetch_array($rs1);

$a=$data1["firstname"];

echo $a;


first line makes those variables global

select * from `nd_staff` where `pcs_ac`='".$_SESSION["UserID"]."'"; pick all the records where pcs_ac (username from domain) is the same as the name of the user who logged into the database pages
$rs1 = db_query($str1,$conn); do the query we just built up with the search string of $str1 and using the connection details held in $conn, put the results in $rs1
$data1 = db_fetch_array($rs1); get that data into an array called $data1
$a=$data1["firstname"]; assign the value held in field firstname to variable $a, FOR THE RECORD JUST CALLED UP
echo $a; print this to the page.
HTH

G