5 replies
I'm trying to exclude some entries in a db that have the date set in the db some entries have under the SOLD colum 0000-00-00 and some have 2012-12-23 so if there is a date there means the vehicle is sold and if it's zero means it's still here..

how can I exclude them that have a date

I'm using SELECT * FROM `cars` WHERE `model`="$userchoice" AND `sold` = "0000-00-00"

is this the best way to do it - or?
#php #question
  • Profile picture of the author ussher
    SELECT * FROM `cars` WHERE 'model' = '$userchoice' AND 'sold = '0000-00-00'

    looks fine, except for the backticks your using for column names.
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[5935969].message }}
  • Profile picture of the author traderookie
    In addition, you may wish to use MySQL Workbench to test your SQL. It is free and can be found MySQL :: Download MySQL Workbench.
    {{ DiscussionBoard.errors[5936147].message }}
  • Profile picture of the author Earnie Boyd
    SELECT * FROM `cars` WHERE `model`='$userchoice' AND `sold` = '0000-00-00'

    I corrected your syntax but other than that it is good. If you've set this up in PHP you want

    $query = "SELECT * FROM `cars` WHERE `model`='{$userchoice}' AND `sold` = '0000-00-00'";
    Signature
    {{ DiscussionBoard.errors[5937343].message }}
  • Profile picture of the author seoking4
    Thanks this is great post.It give me some good tips about PHP.I want to learn more about PHP.
    {{ DiscussionBoard.errors[5943459].message }}
  • Profile picture of the author xrampage16
    While that works, that is not exactly best practices, as well as works for that exact case. It might be better off to convert the date to unix timestamp, and work with it that way. The syntax for converting a string to unix timestamp is...
    UNIX_TIMESTAMP

    and you can read a brief tutorial on it <a href="http://stackoverflow.com/questions/3413559/mysql-convert-mm-dd-yy-to-unix-timestamp">here</a>

    Also, another practice is to grab all of the dates, and then use strtotime in php and manipulate the dates that way.

    so in your instance, you would have done something like...

    I'm using SELECT * FROM `cars` WHERE `model`= "$userchoice" AND FROM_UNIXTIME(`sold`) > 0
    {{ DiscussionBoard.errors[5968046].message }}

Trending Topics