This topic is locked

displaying calculated value on LIST page

9/24/2008 12:02:35 AM
PHPRunner General questions
F
fawad112 author

Hi , thank you all for your great help. I am struck in another problem.

I want to display timeleft with each row on the list page. I can do this with the view page as i can get editid or primary key for this row. But i am unable to do this with list page. Below is the code any help will be appreciated.
I am using this code on the list page before record processed. But i am able to use the $row variable.

Ref is the Primary KEY

[codebox]global $conn ,$smarty;
//if (@$_REQUEST["editid1"])
//** Check if specific record exists ****
$ref = $data["ref"];

$date = "";

$strSQLExists = "select exdate from table where ref='$ref'" and `check` == 1;

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

if (mysql_num_rows($rs) > 0)
{

while ($data = db_fetch_array($rs))
{

$date.=$data["exdata"];
}
$datetime=strtotime( "$date" );

//Retrieve the current date/time

$date2=strtotime("NOW");
if ($datetime < $date2) {

$smarty->assign('pass','Deadline Passed');

} else {
//List total time by type

//Seconds

//echo "total seconds remaining: ".(($datetime-$date2)). "
";

$holdtotsec=(($datetime-$date2));

//Minutes

//echo "total minutes remaining: ".(($datetime-$date2)/60). "
";

$holdtotmin=(($datetime-$date2)/60);

//Hours

//echo "total hours remaining: ".(($datetime-$date2)/3600). "
";

$holdtothr=(($datetime-$date2)/3600);

//

//Days - a day is a 24 hour period

//This gives days remaining

$holdtotday=intval(($datetime-$date2)/86400);
//

//Find hours remaining - get days in hours and sub from tothr

$holdhr=intval($holdtothr-($holdtotday24));
//

//Find minutes remaining - get days and hours in minutes and sub from totmin

$holdmr=intval($holdtotmin-(($holdhr
60)+($holdtotday1440)));
//

//Find seconds remaining - get days hours minutes in seconds and sub from totsec

$holdsr=intval($holdtotsec-(($holdhr
3600)+($holdmr60)+(86400$holdtotday)));
$smarty->assign('holdtotday',$holdtotday);

$smarty->assign('holdhr', $holdhr);

$smarty->assign('holdmr',$holdmr);
}

}

[/codebox]
I can only get the time left for 1 row not all rows.
Thanks in advance

S
steveh 9/24/2008

Do all the calculations in the database query then it's just a normal field for you to deal with.

F
fawad112 author 9/24/2008

i think i cant get time like i want from the database query. I have tried it but it does work. I want to display the output like days hours minutes and the script is working great.. Just need a hint to how to get the id for each row so that i can work on the query

Sergey Kornilov admin 9/24/2008

Set "View as" type of ID field to "Custom" and put your code there.

In this case you can access ID field value using $value

F
fawad112 author 9/24/2008

Can you explain a little plz <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=33399&image=1&table=forumreplies' class='bbc_emoticon' alt=':unsure:' />

Set "View as" type of ID field to "Custom" and put your code there.

In this case you can access ID field value using $value

F
fawad112 author 9/26/2008