1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Do You Know How to do This . . . ?

Discussion in 'PHP' started by Masterful, Sep 7, 2008.

  1. #1
    Anyone know how to ask a simple question with a yes or no answer, then, whatever's picked, have the date on which it was picked be displayed? For example:

    Did this tip work for you?
    Yes | No
    Last worked: 21 October, 2008

    Or:

    Did this tip work for you?
    Yes | No
    Didn't work: 21 October, 2008

    Any help will be rewarded with reputation points. :)
     
    Masterful, Sep 7, 2008 IP
  2. ractors

    ractors Well-Known Member

    Messages:
    1,979
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    140
    #2
    well i am not understand what u wana say can u describe or link where u seen that
     
    ractors, Sep 7, 2008 IP
  3. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Hi,

    Two main columns:
    `lastvalue`
    `lastdate`

    lastdate is a timestamp => www.php.net/date
    lastvalue or 1 or 0 depending on the last click, i.e. 1 = Yes and 0 = No

    I hope that helps :)

    Jay
     
    jayshah, Sep 7, 2008 IP
  4. chanakya

    chanakya Peon

    Messages:
    361
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Insert a date timestampfor every insert
     
    chanakya, Sep 7, 2008 IP
  5. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Not required, as from what I can see from the OP's post, they only want the last event. No point wasting database space with unneeded entries.
     
    jayshah, Sep 7, 2008 IP
    Masterful likes this.
  6. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #6
    Thanks for the help, Jayshah! However, I wish you'd elaborated a bit more.

    Is this how I would create the table in MySQL?

    create table [I]table_name[/I] (
    lastvalue emun("y", "n"),
    lastdate timestamp 
    );
    Code (markup):
    Then, what kind of PHP code would I use on my page?

    I want it to say this at first:

    Worked for you?
    Yes | No


    If someone clicks "Yes", I want it to say:

    Worked for you?
    Yes | No
    Last worked: 02 October, 2008


    If someone then clicks "No", I want it to say:

    Worked for you?
    Yes | No
    Failed: 05 October, 2008
     
    Masterful, Sep 7, 2008 IP
  7. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Hi,

    Sorry for my ambiguity.

    Columns, e.g.:
    `lastvalue` int(1)
    `lastdate` int(15)

    Code to print last click:
    
    $query = mysql_query("SELECT * FROM `table`");
    $data = mysql_fetch_assoc($query);
    if ($data['lastvalue'] == '0'){
        echo "Failed: ";
    } else {
        echo "Last worked: ";
    }
    echo date('d-m-Y', $data['lastdate']); // Change d-m-Y to your desired output using values from www.php.net/date
    ?>
    PHP:
    When updating, you'd do something like:
    $query = mysql_query("UPDATE `table` SET `lastvalue`='{$INPUT}', `lastdate`='".time()."'");
    PHP:
    Where $INPUT is 1 or 0 depending on the click.

    Code is untested, but I hope this guides you further :D

    Jay
     
    jayshah, Sep 7, 2008 IP
  8. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #8
    Jayshah, thank you very much for the help! I appreciate it.

    Reputation points added to your account. :)
     
    Masterful, Sep 8, 2008 IP
  9. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #9
    No problem, thanks for the reputation points :)

    Drop me a line if you need anything else ;)

    Jay
     
    jayshah, Sep 8, 2008 IP
  10. norma

    norma Peon

    Messages:
    23
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    This is a good question and has helped others. Thanks
     
    norma, Sep 8, 2008 IP