Domain Manage

PHP help please

Discussion in 'Scripts and Coding' started by admin, Apr 24, 2011.

Thread Status:
Not open for further replies.
  1. admin Spain

    admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,084
    Likes Received:
    115
    Hi all,

    I am trying to get records from a DB where the date in a field is todays date, or the next day's date:

    Code:
    `fieldname` > date_SUB(CURdate(), INTERVAL 2 DAY)
    doesn't work.

    Any help please?

    Thanks

    Admin
     
  2. Domain Forum

    Acorn Domains Elite Member

    Joined:
    1999
    Messages:
    Many
    Likes Received:
    Lots
     
  3. JDubya

    JDubya Active Member

    Joined:
    Apr 2010
    Posts:
    94
    Likes Received:
    7
    Is the format of the date field in the DB table DATETIME instead of DATE?

    DATETIME = YYYY-MM-DD HH:MM:SS
    DATE = YYYY-MM-DD

    Because CURDATE() returns the date in the format YYYY-MM-DD, which means if the date field was DATETIME then it would not match (the hours, mins, secs throwing it off) .

    If so, you can use DATE_FORMAT to change the value extracted from the DATETIME field. For example:

    PHP:
    SELECT FROM table WHERE DATE_FORMATdatetime_field'%Y-%m-%d' ) = DATE_SUBCURDATE(), INTERVAL 2 DAY )
     
  4. admin Spain

    admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,084
    Likes Received:
    115
    Thanks for the suggestion.

    The field type is "int(10)" and shows a string of numbers which I assume is a Unix format date string.

    Admin
     
  5. JDubya

    JDubya Active Member

    Joined:
    Apr 2010
    Posts:
    94
    Likes Received:
    7
    In that case could try:

    HTML:
    SELECT * FROM table WHERE FROM_UNIXTIME( fieldname, '%Y-%m-%d' ) > date_SUB( CURDATE(), INTERVAL 2 DAY )
     
  6. admin Spain

    admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,084
    Likes Received:
    115
    Didn't work.. no errors but no effect on SELECT statement results either
     
  7. JDubya

    JDubya Active Member

    Joined:
    Apr 2010
    Posts:
    94
    Likes Received:
    7
    Paste in the results of the above query here - might make it easier to spot something...
     
  8. admin Spain

    admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,084
    Likes Received:
    115
    It just selects all the records instead of just the ones with 2 days difference from today's date.
     
  9. admin Spain

    admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,084
    Likes Received:
    115
    Got that sorted after playing about for hours.

    Now I'm build a PHP to RSS script, how do I add a URL link in the following line:

    Code:
    $rssfeed .= '<link>' . $classifiedid . '</link>';
    so link to http://www.acorndomains.co.uk/vbclassified.php?do=ad&id=[$classifiedid field here]

    Thanks

    Admin
     
  10. seemly

    seemly Active Member

    Joined:
    Feb 2011
    Posts:
    973
    Likes Received:
    39
    admin sorted code anyway. =)
     
    Last edited: Apr 26, 2011
  11. admin Spain

    admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,084
    Likes Received:
    115
  12. admin Spain

    admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,084
    Likes Received:
    115
    In the auctions i only want the "view bids" to show if the auction has bids, how do I do that?

    I also want to link (join) to another table to get the number of bids...

    thanks

    Admin
     
  13. killaclown

    killaclown Active Member

    Joined:
    Feb 2006
    Posts:
    311
    Likes Received:
    7
    hi admin,

    you probably already know, but i think maybe,

    IF bidcount row >= 1 {

    show }

    else {
    "be the first to bid" (whatever)
    }

    i could give a better answer if i could see the code, table/feild names.

    pm me if you want me to have a "proper bash" tomo.
     
  14. admin Spain

    admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,084
    Likes Received:
    115
    I'm already using the IF and ELSE to alternate the row colours. How do I do both?
     
  15. killaclown

    killaclown Active Member

    Joined:
    Feb 2006
    Posts:
    311
    Likes Received:
    7
    Hi admin,

    Im dont know the names of your rows or excatly how you've done the if/elses for the row colours, but maybe something like this,



    your IF (condition for row colour) {

    your if code for row colour;

    /* new if stament */ IF (yourbidcount.row >= 1) {

    print ("<a href=\"linkToBidPage/\">view bids</a> ");

    }



    else {

    print("be the first to bid");

    }

    }

    your else {

    your else code for the row colour

    /* new if stament */ IF (yourbidcount.row >= 1) {

    print ("<a href=\"linkToBidPage/\">view bids</a> ");

    }



    else {

    print("be the first to bid");

    }

    }


    }


    Its a bit messy, but should work.
     
Thread Status:
Not open for further replies.

Share This Page