Solved

if statement not displaying my statement

Posted on 2013-10-30
11
246 Views
Last Modified: 2013-10-30
I am trying to change what is displayed by using an if statement to change the value.

 After I have queried database, instead of having '00-00-0000' in the date field if there is no date set, i would change it to 'No date set'. However, this is not updating the display with that text. Can someone point out where I have gone wrong in my code. Thanks

$query_rs_rpt_in = sprintf("SELECT * FROM boxes WHERE customer = '%s'AND COALESCE(custref,'') != ''", $colname_rs_rpt_in);

Open in new window


<?php 	

      if ($row_rs_rpt_in['boxin_date'] == '00-00-0000')
		     
             {echo 'No date set';}
      else 
             {echo KT_formatDate($row_rs_rpt_in['boxin_date']);} 

?>

Open in new window

0
Comment
Question by:peter-cooper
  • 5
  • 4
  • 2
11 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39611621
0
 

Author Comment

by:peter-cooper
ID: 39611630
Sorry Ray, do not understand your answer. Thanks
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39611654
Read the article.  There is a standard for date formats in computing.  ISO-8601 makes life easier because it creates predictable formats for date/time strings.

Executive summary:

1. Define your table columns with data type = DATE or DATETIME
2. Make the default value '0000-00-00 00:00:00'
3. Convert all date representations to ISO-8601 with the date('c') formatter.
4. Magically, your date computations will start to work sensibly!
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39611665
var_dump the data and you'll see instantly whether it should match:

var_dump($row_rs_rpt_in['boxin_date']);
if ($row_rs_rpt_in['boxin_date'] == '00-00-0000') {
   echo 'No date set';
} else {
   echo KT_formatDate($row_rs_rpt_in['boxin_date']);
} 

Open in new window

If your database is not returning EXACTLY 00-00-0000 then your IF won't match - it's unlikely as dates are usually stored as YYYY-MM-DD, so it's probably 0000-00-00!
0
 

Author Comment

by:peter-cooper
ID: 39611705
@Chris

It shows as this: string '0000-00-00' (length=10) so I have changed but I also think I need to change and check for and NULL entries. How would I check for NULL Chris.
0
 

Author Comment

by:peter-cooper
ID: 39611710
@Ray Thank you
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39611733
Like this:

if ($row_rs_rpt_in['boxin_date'] == '0000-00-00' || is_null($row_rs_rpt_in['boxin_date']) {

Open in new window

You might also need to check for '' using empty($row_rs_rpt_in['boxin_date']).

A better option, depending on your needs would be to setup your Date column to have a default value of 0000-00-00 and not accept NULL
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39611747
Edit...

2. Make the default value '0000-00-00 00:00:00' for DATETIME columns
2.A. Make the default value '0000-00-00' for DATE columns
2.B. Make both types NOT NULL
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39611813
Considering this and your other question about how to handle dates in data bases, you might want to read this brief but thoughtful article from another of our colleagues here at EE.
http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/A_11210-Beware-of-Between.html
0
 

Author Closing Comment

by:peter-cooper
ID: 39612387
Thanks once again Chris.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39612659
NP.  I think you can change the contents of the solution :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Displaying text in text field when clicking on ajax search result 10 39
Ajax and PHP 4 30
Checking https returns 301 21 21
$_SERVER Variable question 31 27
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question