Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

Help with conditional logic

I only want to show the selected table row if the auction endDate is greater then the current date and not show it if the auction is either over; meaning less then current date; the way I did it is not working

<?php
// Show IF Conditional region1
if (@$row_rssearchResults['endDate'] > "date(\'Y-m-j\')") {
?>
                <tr>
                  <td>Place Bid </td>
                  <td><form id="form1" name="form1" method="post" action="place-bid.php?id=<?php echo $row_rssearchResults['auctionID']; ?>">
                    <input name="Submit" type="image" value="Place Bid" src="images/placebid.gif" />
                  </form></td>
                </tr>
                <?php }
// endif Conditional region1
?>
0
vonfranzken
Asked:
vonfranzken
  • 2
2 Solutions
 
Beverley PortlockCommented:
Try changing

if (@$row_rssearchResults['endDate'] > "date(\'Y-m-j\')") {

to

if ( $row_rssearchResults['endDate'] > date('Y-m-d')  ) {

This does assume that $row_rssearchResults['endDate'] is in YYYY-MM-DD format
0
 
Ray PaseurCommented:
This article will tell you how to handle DATETIME information in PHP and MySQL:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

You really want to be using the ISO 8601 standard format for these date and time strings, believe me!

Also, this statement does not really make sense.  The @ is used to suppress error messages from functions - you almost never want to suppress error messages, instead you want to correct them.

if (@$row_rssearchResults['endDate'] > "date(\'Y-m-j\')") {

And the date() function, like all PHP functions, is documented in the online man pages, with good examples and user-contributed notes.  When you are not 100% sure what a function does, it's a good idea to read the page and the notes.  Example here:
http://us.php.net/manual/en/function.date.php
0
 
Ray PaseurCommented:
It's often a good idea to use data visualization techniques to see what your programming is doing to the data.  Example:
http://www.laprbass.com/RAY_temp_vonfranzken.php

Outputs:
string(15) "date(\'Y-m-j\')"
string(10) "2011-04-19"
string(25) "2011-04-19T06:41:47-05:00"

HTH, ~Ray
<?php // RAY_temp_vonfranzken.php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');
echo "<pre>";

// SHOW THE ORIGINAL DATA STRING
$str = "date(\'Y-m-j\')";
var_dump($str);

// TRY THE FUNCTION RESULT WITH THE STRANGE ESCAPE CHARACTERS INTACT
// $str = date(\'Y-m-j\'); // COMMENTED OUT - CREATES A PARSE ERROR
// var_dump($str);

// SHOW THE DATE STRING
$str = date('Y-m-j');
var_dump($str);

// SHOW THE ISO8601 DATETIME STRING
$str = date('c');
var_dump($str);

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now