Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two questions... Date and If Statement

Status
Not open for further replies.

Vermontecher

Programmer
Feb 13, 2005
14
0
0
US
Hello,
I am new to PHP and I am trying to do something that I could do in ASP with my eyes closed, but PHP is so much different. Here are the two things I thought would be simple...

1.) I want to display data from the database according to a start and end date. In ASP I would use the following code...

Where "[Activate]=True AND [StartDate]< #" & CDate(Date) & "# AND [EndDate]> #" & CDate(Date) & "#"

Can someone tell me what I would use in PHP please, it would be greatly appreciated.



2.) The next item seemed to be a lot simpler, but I can't seem to get it. I want to display something according to a field in a database. Here is the code I now have...

<?php if ($x_field1 != 0) { ?>
0
<?php } ?>

<?php if ($x_field1 != 1) { ?>
1
<?php } ?>

<?php if ($x_field1 != 2) { ?>
2
<?php } ?>

<?php if ($x_field1 != 3) { ?>
3
<?php } ?>

The value of field1 in the database is set to 2, but when I view the page what is displayed is 0 1 3 and no 2. I would have thought that if the value of field1 were 2 it would disregard the 0 1 3 and display the 2, but that is not the case. If I could get some direction on this I would be forever grateful.

Thanks
VermontTecher
 
Hi Vermont,

Im not sure on No1 but for No2 something like the following should work.

Code:
switch ($field1){
   case "0":
   // do this is field1 = 0
   break;
   case "1":
   // do this if field1 = 1
   break;
   case "2":
   // do this if field1 = 1
   break;
   case "2":
   // do this if field1 = 1
   break;

}

I wish someone would just call me Sir, without adding 'Your making a scene'.

Rob
 
Sorry, code should be as follows; (too much copy and pasting plus beer)


Code:
switch ($field1){
   case "0":
   // do this is field1 = 0
   break;
   case "1":
   // do this if field1 = 1
   break;
   case "2":
   // do this if field1 = 2
   break;
   case "3":
   // do this if field1 = 3
   break;

}

I wish someone would just call me Sir, without adding 'Your making a scene'.

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top