Hey guys,
im working on something new for my site, some kind of function that will show every 2 weeks how many dogs have been abandoned and how many have been adopted in the previous 2 weeks, this function will work like that:
i built a new table in my DB, with the coluums Abandoned and Adopted, both are numbers and starting at 0, and a date field (i think it should be a date field, which will work automatic and every 2 weeks will publish the info in the homepage)
All fields gets reseted after publishing is done
whenever a manager adds a dog for adoption to the website, then the abandoned field gets +1
whenever a manager moves a dog from the adoption table to the adopted table, then the adopted field gets +1
Note: numbers cannot become negative
i think thats all, i can do everything myself besides of the auto publishing every 2 weeks part, im going to need help on how can i achieve this.
also, if any1 got a better idea on how to do the above in a better way, i’d like to know about it
ASP/Windows hosts tend not to allow you to set up scheduled tasks (on Linux hosts this is commonly known as CRON). So a workaround would be for you to set up a scheduled task on a windows PC to open a web browser and call up an ASP page that runs your code to do the updates.
oh, nvm then, ill pass, thought it could be achieved with one of the Date() functions or so, i’d just make a page with a button named “publish” and just use it every 2 weeks myself then
At least can i do something like this, so every day passed it adds +1 to a day field in my DB automatically? so when i press the publish button it’ll write something like that:
“there were xx dogs adopted and xx dogs abandoned in the last XX days”
It depends on your host… Some Windows hosts do let you schedule tasks but you’ll have to get in touch with them and find out. That said, I don’t think it’s necessary for what you want to do.
Instead of just having a tables that have +1, why not have a table for Abandoned and a table for Adopted and just have a time/date field so when a dog is brought in an entry with a datestamp is inserted. When a dog is adopted a datestamp is inserted. Then for the homepage status you just do a count query on each table for the current month.
you could reduce this to one table and have two columns. One for the date and another for the status:
Hey awasson, a cool idea indeed but i got a bad time understanding how that acutally works, first, whats a datestamp ?
from the other side, i got everything ready already besides of the Days field, also, the details doesn’t go straight to the home page, i got a page where i can publish the infos from (this is also good in case i dont want to show this details anymore)
So if there’s a way of getting the amount of days passed until publishing is done this would also help (something lilke the current date minus the date the first abandoned or adopted dog have been added to get the amount of days passed)
Well if you’re using MS Access for your database you would create a table called something intuitive like adoption_ratio or something like that.
I would have three columns and set it up in design view:
ID - AutoNumber, Primary Key
EventDate - Date/Time (set the default value to “now()”)
EventType - Integer (0=Abandon 1=Adoption)
The only things that go into this database the 0 or 1 representing an abandonment or an adoption. Timestamp is created automatically.
You aren’t using the ID but I always create one out of habit.
Then you do a Select * FROM adoption_ratio where EventDate is between the two week period AND EventType = 1 or 0 depending on whether you’re looking for adoptions or abandons.
It’s as simple as that
EDIT: Actually you would do a select count but it’s pretty much all there for you.
New to the Program Your Site forums? Please read this
well, u post the same comment over and over, until now i tried to ignore it but really, cant anymore.
i just tried to write “datestamp” in google to see how good google is in explaining… and yeah the topics i got as results are awesome, not even close to what i am looking for. so please…
and btw, thanks for the link, altho im not a new member of sitepoint since a long time already
now ontopic, thanks awasson for the help, but how do i get the 2 weeks period?
Then you do a Select * FROM adoption_ratio where EventDate is between the two week period AND EventType = 1 or 0 depending on whether you’re looking for adoptions or abandons.