How to get date from database ?
Hey, i have a question... I need to get date from database from field date (yyyy-mm-dd or yyyy-dd-mm) then take away todays date, and get number what i need to show on server when user type one command.
Example: In database 2011-15-08, server get it and take away 2011-20-07 and when user type command he get something like this "You have 25 more days". |
Re: How to get date from database ?
It would be easier to work with unix timestamps. You can save a unix timestamp
as int in the database. then you just subtract the current time with the saved time and you have the seconds which you can calculate into days. MySQL Date should be possible too but then you better do the day calculation with MySQL functions. |
Re: How to get date from database ?
Okey, but how i can do it ? I tryed many things, but i can't do it.
|
Re: How to get date from database ?
you can't get unix_timestamps or you can't get the mysql date functions to work?
if you want to use unix timestamps (take a look at FROM_UNIXTIME) just subtract the ints and you get the seconds between both dates. if you want to utilize mysqls builtin stuff take a look at DATEDIFF and the examples. also: what did you try and why did it fail? |
Re: How to get date from database ?
I'am a beginner in this and I don't now how to do it :( I tryed it with SQL_TQuerry.
Please show me this in code and I understand it. |
Re: How to get date from database ?
Quote:
with the links i gave earlier and this you can figure everything out yourself. also there are enough examples/plugins in the forums which could help you a lot. its btw much more rewarding to do this yourself, than just get code to copy&paste... |
Re: How to get date from database ?
Okey, i tryed it but where is my error ?
PHP Code:
|
Re: How to get date from database ?
Quote:
PHP Code:
But you don't want to print in there to begin with, because you are using a threaded query, which means you won't have the results ready after calling CheckDate, but only after T_CheckDate has been called. Only then you could use your results e.g. to print them. PHP Code:
I also thought you wanted to check how many days a certain user has left, so your query should rather be sth like this: "select last_date FROM users WHERE steamid = 'STEAM_0:1:12314'". Furthermore you'll never do anything with the result you get from the database (which you should do in T_CheckDate()). As a principal hint: Don't try to do everything at once, but start slow and grow your code. So you first want to have the correct SQL query, use phpMyAdmin or whatever you are comfortable with to create and test your query. If you are getting the results you want (steamid + last_date), proceed to your plugin and use non-threaded queries. If those work, rewrite your code to use threaded queries. You are currently trying to do all at the same time, which is bound to fail if you are new to all of them. |
Re: How to get date from database ?
Sorry, but i can't understand it :( I want to give last date of user premium
I do this, but server show me SQL_FetchInt reported: Invalid query Handle 7e0077 (error: 2) PHP Code:
|
Re: How to get date from database ?
ok, you obviously tried to help yourself. :up:
i like that, so here's some more help: i quickly wrote this to push you in the right direction. i guess almost everything you need is in there. this is completely untested and you also need to adapt the db name and stuff. this is just meant as an example which you can heavily copy+paste. but please, still try to understand what's happening. if you have any further questions, feel free to ask. PHP Code:
|
All times are GMT -4. The time now is 18:05. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.