View Full Version : Do You Know How to do This . . . ?
Masterful
Sep 7th 2008, 11:01 am
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. :)
ri12ku2002
Sep 7th 2008, 11:10 am
well i am not understand what u wana say can u describe or link where u seen that
jayshah
Sep 7th 2008, 11:12 am
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
chanakya
Sep 7th 2008, 11:25 am
Insert a date timestampfor every insert
jayshah
Sep 7th 2008, 11:29 am
Insert a date timestampfor every insert
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.
Masterful
Sep 7th 2008, 7:32 pm
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
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 table_name (
lastvalue emun("y", "n"),
lastdate timestamp
);
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
jayshah
Sep 7th 2008, 11:48 pm
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
?>
When updating, you'd do something like:$query = mysql_query("UPDATE `table` SET `lastvalue`='{$INPUT}', `lastdate`='".time()."'");
Where $INPUT is 1 or 0 depending on the click.
Code is untested, but I hope this guides you further :D
Jay
Masterful
Sep 8th 2008, 12:55 pm
Jayshah, thank you very much for the help! I appreciate it.
Reputation points added to your account. :)
jayshah
Sep 8th 2008, 1:03 pm
No problem, thanks for the reputation points :)
Drop me a line if you need anything else ;)
Jay
norma
Sep 8th 2008, 5:31 pm
This is a good question and has helped others. Thanks
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.