This topic is locked

'View as' Custom - if-clause in Visual Editor

7/18/2007 3:13:17 AM
PHPRunner General questions
W
wrjost author

Hello, everybody,

my project is a tournament registration database for teams, consisting of a master table "tblTournament" and a table "tblTeams". There are two important fields: "registration deadline" in "tblTournament" and "reference time" in "tblTeams".
My problem:

when guests visit the site to see which teams have registered so far for a given tournament, they are not to see the reference time of any team until the registration deadline for that tournament has passed. In the Visual Editor I have declared the respective field to be "Custom" and now I am struggling with the PHP-code to go there. I want it to function like this:
[codebox]if (now()>tblTournament.deadline) then

$value=$value

else

$value="0";[/codebox]
Sorry, I am new to PHP, this is how I would do it in Delphi... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=5792&image=1&table=forumtopics' class='bbc_emoticon' alt=':rolleyes:' />
Any ideas?
Thank you in advance from Germany.
Regards,

Wilfried

J
Jane 7/18/2007

Wilfried,
you need to select tblTournament.deadline and then compare it with current date.

Here is a sample code:

global $conn,$data;

$str = "select deadline from tblTournament where TournamentID=".$data["Teams_TournamentID"];

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

$data2 = db_fetch_array($rs);

if ($data2["deadline"]>now())

$value="";



where TournamentID is your actual field date in the tblTournament table, Teams_TournamentID is your actual field name in the tblTeams table.
Also I recommend you to have a look at PHP documentation:

http://www.php.net/manual/en/

W
wrjost author 7/18/2007

Hello, Jane,

your suggestion worked partially - even tough I have added the date-function,
[codebox]if ($data2["deadline"]>date(now())) $value="";

echo $data2["deadline"];

echo date(now());[/codebox]
I still have the problem that "deadline" is a date (e.g. "2007-07-18") and "now()" includes the time (e.g. "2007-07-18 15:39:55") - and date(now()) does not seem to work the way the php-manual says it should with formatting of "Y-m-d".
So, for the tournament with a deadline (="Meldeschluss") of today, it still shows all the reference times, whereas it should keep them blank until midnight.
wrong - tournament with deadline today
o.k. - tournament with deadline in the future
o.k. - tournament with deadline in the past
Can you please help and show me how the code needs to be corrected?
Thank you again,

Wilfried