This forum is archived. Posts are preserved for historical reference. For current help, join us on Discord.

Retrieving data from database

In Modifications and Hackery · Started by LBC on 2019-01-04 9:02 am · 154853 views · 66 replies

Hello Mudmin, I have another question :)

I have added a column to the database named "validity". I want to add dates at which a membership card was bought in there.

There are two kinds of cards...one that is valid 6 months and one that is valid 12 months.

I was hoping there would be an echo possible in which I could specify whether the card is 6 or 12 months valid so the displayed date would be set accordingly.

So for instance, a 6 month card bought on January 1st 2019 would echo out "valid till: July 1st 2019"
Can you give me an idea of how the date is stored in the db? Is it date or datetime?
Well, I have set it to just date right now (as an added time would be unnecessary).
So I guess the first of January 2019 will be stored as "2019-01-01

If datetime is better...than that is fine too :)
Nope. That's perfect.
Give me a min.
Is that validity column in the users table of the db?
And random question...why don't you just add 6/12 months to the date before you add it to the db?

Is that validity column in the users table of the db?

Yes, its is.

And random question...why don't you just add 6/12 months to the date before you add it to the db?

ehm...because then I would have to calculate it myself and an error could be made.
If the computer does it...there can be no mistake..well...theoretically
So if you want to show 6 months from the date in the db it's
$date = date('Y-m-d', strtotime("+6 months", strtotime($user->data()->validity));
dump($date);

If you want to add the time before you put it in the db, it's...
$date = date('Y-m-d', strtotime("+6 months", strtotime(date("Y-m-d"))));
$db->update('users',$user->data()->id,['validity'=>$date]);

So if you want to show 6 months from the date in the db it's
$date = date('Y-m-d', strtotime("+6 months", strtotime($user->data()->validity));
dump($date);

If you want to add the time before you put it in the db, it's...
$date = date('Y-m-d', strtotime("+6 months", strtotime(date("Y-m-d"))));
$db->update('users',$user->data()->id,['validity'=>$date]);

so, no echoing?
I'm not sure I'm understanding. So you have a date in the db that is the date that the item was purchased. How do you know if it is a 6 month or 12 month one?
I can see that from another filled in column which is called membership.
It either says 10cc or 5cc in there (10cc is 12 months, 5cc is 6 months)
Ok.  So it will be something like this.
However you figure out the length, it needs to wind up as a 6 or 12.
$length = 6;  

then
echo date('Y-m-d', strtotime("+".$length." months", strtotime($user->data()->validity)));

Ok.  So it will be something like this.
However you figure out the length, it needs to wind up as a 6 or 12.
$length = 6;  

then
echo date('Y-m-d', strtotime("+".$length." months", strtotime($user->data()->validity)));

like this?

<?php echo date('Y-m-d', strtotime("+".$length=6." months", strtotime($user->data()->validity))); ?><
Can you tell me what column stores the length and what the length looks like? Is it a word? is it 6 or 12?

Can you tell me what column stores the length and what the length looks like? Is it a word? is it 6 or 12?

the length is stored in the "membership" column and is either 10cc or 5cc (10 = 12 months / 5 = 6 months).
I could call it 10 or 5 also if that would be better.
Nope. That's fine.
if($user->data()->membership == '5cc'){
$length = 6;
}elseif($user->data()->membership =='10cc'){
$length = 6;
}
if(isset($length)){
echo date('Y-m-d', strtotime("+".$length." months", strtotime($user->data()->validity)));
}

I think that will do it.

Nope. That's fine.
if($user->data()->membership == '5cc'){
$length = 6;
}elseif($user->data()->membership =='10cc'){
$length = 6;
}
if(isset($length)){
echo date('Y-m-d', strtotime("+".$length." months", strtotime($user->data()->validity)));
}

I think that will do it.

I'm afraid it doesn't display anything now. I have done it like this now:

<p><strong>Valid until:</strong>
        <?php if($user->data()->membership == '5cc'){
        $length = 6;
        }elseif($user->data()->membership =='10cc'){
        $length = 12;
        }
        if(isset($length)){
        echo date('Y-m-d', strtotime("+".$length." months", strtotime($user->data()->validity)));
        }?></p>

[quote='mudmin' pid='7310' dateline='1548162681']
Nope. That's fine.
if($user->data()->membership == '5cc'){
$length = 6;
}elseif($user->data()->membership =='10cc'){
$length = 6;
}
if(isset($length)){
echo date('Y-m-d', strtotime("+".$length." months", strtotime($user->data()->validity)));
}

I think that will do it.

So this is going to show the length for the logged in user. Does your account have a membership and validity set?

[/quote]

[quote='LBC' pid='7311' dateline='1548163067']
[quote='mudmin' pid='7310' dateline='1548162681']
Nope. That's fine.
if($user->data()->membership == '5cc'){
$length = 6;
}elseif($user->data()->membership =='10cc'){
$length = 6;
}
if(isset($length)){
echo date('Y-m-d', strtotime("+".$length." months", strtotime($user->data()->validity)));
}

I think that will do it.

So this is going to show the length for the logged in user. Does your account have a membership and validity set?

[/quote]

[/quote]

yes, bought a 10cc on january 20th 2019

admin_user.jpg
I can fill that in on the admin_user form...see attachment
Can you paste the chunk of the form itself from the input of time through lessons left? Maybe copy the code and paste on pastebin and share the link here.
‹ Prev1234Next ›