Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So i have the following query

   query = "SELECT date_format(startPeriod,'%a, %M, %d, %Y') as startDate,
             date_format(startTime,'%I:%i%p') as startTime,
             date_format(endTime,'%I:%i%p') as endTime,
             jobLocation,jobId,
              hoursWorked
       FROM users,paycheck
       WHERE users.userId = '" . $_SESSION['userId'] .
       "' AND userId = empId
       AND startPeriod IS NOT NULL
       ORDER BY paycheck.startPeriod DESC";

The problem is that some of the values of startPeriod( which is a date) are null so when i run my query I dont want to show those dates which are null, but unfortunately dates that are null show up on my table . How can I fix this?

this is my output file on my source

  <tr><td></td><td>12:00AM</td><td>12:00AM</td><td>none</td><td>none</td><td>0.00</td></tr>

In between the first tds you can see its empty

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
213 views
Welcome To Ask or Share your Answers For Others

1 Answer

Are you sure that the data inserted is actually NULL, and not just an empty string?

After that replace startPeriod IS NOT NULL to TRIM(startPeriod) <> ""

OR

query = "SELECT date_format(startPeriod,'%a, %M, %d, %Y') as startDate,
             date_format(startTime,'%I:%i%p') as startTime,
             date_format(endTime,'%I:%i%p') as endTime,
             jobLocation,jobId,
              hoursWorked
       FROM users,paycheck
       WHERE users.userId = '" . $_SESSION['userId'] .
       "' AND userId = empId
       AND (startPeriod != '0000-00-00' OR startPeriod IS NOT NULL)
       ORDER BY paycheck.startPeriod DESC";

may this help you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...