View Full Version : grr Last Bred
SilverDragonTears
08-09-2011, 09:33 PM
is printing out weird numbers. how can i get it to show the date? I'm getting super annoyed =(
SilverDragonTears
08-10-2011, 02:51 PM
This is going to make me lose my mind =(
Chibi_Chicken
08-10-2011, 04:58 PM
It looks like the last bred just stores the return value of time()
http://php.net/manual/en/function.time.php (for more info)
you could echo out the date with the date function, like:
date('Y-m-d', $lastweek) to see what it is.
beyond that I am not sure, I haven't work with the time() or the breeding script that much.
SilverDragonTears
08-10-2011, 05:11 PM
where do i put that?
SilverDragonTears
08-10-2011, 05:17 PM
ok I put it like this
Last bred: ".date('Y-m-d', $lastweek)."
and got
Last bred: 1969-12-31
Chibi_Chicken
08-10-2011, 05:47 PM
well that is a long time ago. so what are you trying to do with the last bred just display it as a date?
SilverDragonTears
08-10-2011, 05:49 PM
Yes I want it displayed so that the members know when they last bred each pet. And if they haven't been bred yet, display nothing. That's not the hard part though... the hard part is getting it to display the date they were bred.
Chibi_Chicken
08-10-2011, 06:24 PM
ok, so i understand the problem more now.
so when you get last bred from the adopt it displays
1969-12-31
i would get the adoptable last bred and then display
echo date('Y-m-d', $lastbred);
echo date('Y-m-d', time());
See what the difference is, I dont know why it is giving 1969. Sorry I used $lastweek that is a misleading variable.
SilverDragonTears
08-10-2011, 07:14 PM
neat... it gives me
Last bred: 2011-08-10
2011-08-10;
So I guess I can remove one?
SilverDragonTears
08-10-2011, 07:19 PM
hmmm i'm confused... this is my code.
if($lastbred == '') {
$article_content .= '';
} else {
$article_content .= 'Last bred: '.date('Y-m-d', $lastbred).'<br>
'.date('Y-m-d', time()). '<br>';
}
some caught eggs are showing
Last bred: 1969-12-31
2011-08-10
but the rest print nothing including laid eggs which is how it's suppose to be
oh i see why... some say nothing for last bred and some say 0. how can i fix that?
and a pet i bred today shows
Last bred: 2011-08-10
2011-08-10
SilverDragonTears
08-10-2011, 07:30 PM
ooo I think i got it...
if($lastbred == '') {
$article_content .= '';
}
else if($lastbred == '0') {
$article_content .= '';
} else {
$article_content .= 'Last bred: '.date('Y-m-d', $lastbred).'<br>
'.date('Y-m-d', time()). '<br>';
}
But the adults that have bred are still printing out two dates so remove the second date echo?
Chibi_Chicken
08-10-2011, 07:46 PM
$lastbred will need to be assigned a value. this value is going to come from the DB owned_adoptables lastbred column. So I am not sure where you are putting this but one way you can do it is.
//you will need to supply the $id of the adoptable
$result = runquery("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$id'") ;
$lastbred = @mysql_result($result,0,'lastbred');
//now display the results
if($lastbred == '') {
$article_content .= '';
} else {
$article_content .= 'Last bred: '.date('Y-m-d', $lastbred).'<br>';
//i took out the second one unless you wanted to show the current day.
}
Their is a couple of problems with this. if the script is looping $result and you run this it will break the code, second this is a waste of resources if you all ready have the information you need from another $result you dont need to run another sql request. It will slow the site down.
I hope I am explaining this clearly :el: If you want, what php page are you trying to add this in to, I can test it out latter when I am at work and see if I can make better sense of it.
ATM I am kinda of distracted with Terraria ^.^;
SilverDragonTears
08-10-2011, 07:58 PM
LoL I kept posting so I think you missed mine... I think I got it =p
This:
if($lastbred == '') {
$article_content .= '';
}
else if($lastbred == '0') {
$article_content .= '';
} else {
$article_content .= 'Last bred: '.date('Y-m-d', $lastbred).'<br>';
}
Seems to be working well! Wouldn't have been able to do it without your help though =) Thank you.
This is completely unrelated to this issue...
But I added in Date Caught/Bred and the ones that were already caught or bred before this was added have no dates. Is there an easy way to insert into the database a default date for those who don't have one?
Chibi_Chicken
08-10-2011, 08:47 PM
You are welcome. :)
you can run something like
UPDATE table SET Date Caught/Bred = '0' WHERE Date Caught/Bred = ''
SilverDragonTears
08-10-2011, 08:53 PM
do I do that in the phpadmin panel?
SilverDragonTears
08-10-2011, 08:57 PM
uh oh... i did this
UPDATE `adopts_owned_adoptables` SET `date`=2011-08-10 WHERE date=0000-00-00
and it put 1993 in there LOL
Shoot I keep double posting =( Sorry guys!!
Got it =) It was
UPDATE adopts_owned_adoptables
SET date='2011-08-10'
WHERE date='1993'
Chibi_Chicken
08-11-2011, 01:14 AM
that is cool that you got it working. :)
question in your DB what type is date is it a varchar or date format, and when comparing dates in php do you have to do anything special?
SilverDragonTears
08-11-2011, 01:38 AM
it's varchar... and not sure I understand the second question
Chibi_Chicken
08-11-2011, 02:58 AM
well I just wonder what would happen when you compare $date with $currentdate
like $date = '2010-08-10'
$currentdate = '2011-08-11'
if $date < $currentdate
"your adopt is able to do something"
I guess what I am confused about is how comparing strings work, because php doesnt know that tho two variables are dates, or at least I dont think it knows.
I will have to look in to it.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.