News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Is this a way I can edit MySQL table value?

Started by General Xbox Gaming, September 30, 2014, 02:08:05 PM

Previous topic - Next topic

General Xbox Gaming

It still needs to be refreshed! How would I make a link to refresh the page if the

$user_member[$memID]['id_group'] == ("1" OR "2" OR "3" OR "10")

in Load.php or Profile-template.php

Arantor

$user_member[$memID]['id_group'] == ("1" OR "2" OR "3" OR "10")

Isn't going to work. It's going to crash and burn because "1" OR "2" OR "3" OR "10" becomes truthy OR truthy OR truthy OR truthy becomes bool true, which maps to 1, so you end up doing this only for id_group 1 which is the admin group.

Though I have no idea what $user_member is, I assume you mean $user_profile.

In which case... in_array($user_profile[$memID]['id_group'], array(1, 2, 3, 10))

(I still have no understanding why everyone puts numbers in quotes when they're not strings.)
Holder of controversial views, all of which my own.


General Xbox Gaming

Quote from: Arantor on October 11, 2014, 02:10:30 PM
$user_member[$memID]['id_group'] == ("1" OR "2" OR "3" OR "10")

Isn't going to work. It's going to crash and burn because "1" OR "2" OR "3" OR "10" becomes truthy OR truthy OR truthy OR truthy becomes bool true, which maps to 1, so you end up doing this only for id_group 1 which is the admin group.

Though I have no idea what $user_member is, I assume you mean $user_profile.

In which case... in_array($user_profile[$memID]['id_group'], array(1, 2, 3, 10))

(I still have no understanding why everyone puts numbers in quotes when they're not strings.)
Maybe because I didn't know how to use it in an array statement! Thank you for showing me how it's done but how do I make a text link that refresh's the current page?

margarett

Maybe it's easier if you attach your current Profile-View.php ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

You could even update $context after changing the database to avoid a reload, just as a thought.
Holder of controversial views, all of which my own.


General Xbox Gaming

#45
Quote from: Arantor on October 11, 2014, 07:57:09 PM
You could even update $context after changing the database to avoid a reload, just as a thought.
Doesn't work, still requires reloading the users profile page.

if (empty($context['member']['product_key']) AND in_array($context['member']['id_group'] == array(1,2,3,10)))

echo '
<dt> Product Key: </dt>
<dd><a href="?action=profile">Refresh!</a></dd>'
;

elseif (!(
$context['member']['product_key'] == ""))

echo '
<dt> Product Key: </dt>
<dd>'
, $context['member']['product_key'], ' </dd>';
else
echo '
<dt> Product Key: </dt>
<dd><a href="?action=profile;area=subscriptions;u='
, $context['member']['id'], '">Buy Now</a></dd>';


The first "if" doesn't work correctly! This is in Profile.template.php

Can you show me how this should be done correctly please?

Arantor

Of course it doesn't. Using in_array wrong is guaranteed to make it not work correctly.

if (empty($context['member']['product_key']) && in_array($context['member']['id_group'], array(1,2,10)))

There is no point including group 3 since there's absolutely no way (unless something else got broken) group 3 will ever be on a user while in the profile area.

As for my comment... whatever logic you had (in the Profile-View.php file) for determining if it was empty and generating a new one... update the database, then push it to $context, would simplify this logic. You would cut out the need to refresh entirely because you'd already have it to display, but of course this is not relevant.

I'm really sorry... I just can't do this. I was trying to help with this but I just can't. This is just going to take more patience than I have to make this work for you the way you want it.
Holder of controversial views, all of which my own.


General Xbox Gaming

No matter what I do, the 'id_group' always returns false so it's skipping that and moves on to the elseif & else. Wouldn't be a problem but if 'product_key' is empty and the 'id_group' is actually true, it comes up with "Buy Now" instead of "Refresh!", which is a problem!

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

General Xbox Gaming

Quote from: margarett on October 11, 2014, 07:43:47 PM
Maybe it's easier if you attach your current Profile-View.php ;)
I've been doing this on my iPhone because I've been busy with work. I will attach the file later when I get home. I have a different key generator so I will change that part before I upload it.

Arantor

Quote from: General Xbox Gaming on October 12, 2014, 08:29:28 AM
No matter what I do, the 'id_group' always returns false so it's skipping that and moves on to the elseif & else. Wouldn't be a problem but if 'product_key' is empty and the 'id_group' is actually true, it comes up with "Buy Now" instead of "Refresh!", which is a problem!

So instead of changing code at random, would it not have been better to say this before?

In this case, I forgot that loadMemberContext is strange. Use $context['member']['group_id'] for primary group instead.
Holder of controversial views, all of which my own.


General Xbox Gaming

Quote from: Arantor on October 12, 2014, 01:35:55 PM
Quote from: General Xbox Gaming on October 12, 2014, 08:29:28 AM
No matter what I do, the 'id_group' always returns false so it's skipping that and moves on to the elseif & else. Wouldn't be a problem but if 'product_key' is empty and the 'id_group' is actually true, it comes up with "Buy Now" instead of "Refresh!", which is a problem!

So instead of changing code at random, would it not have been better to say this before?

In this case, I forgot that loadMemberContext is strange. Use $context['member']['group_id'] for primary group instead.
BINGO!

Thank you Arantor, how do I just refresh the page they are on rather then "?action=profile" unless I do "?action=profile;u=', $context['member']['id'], '"

Arantor

Why are you so insistent on trying to refresh the page?
Holder of controversial views, all of which my own.


General Xbox Gaming

Quote from: Arantor on October 12, 2014, 03:25:39 PM
Why are you so insistent on trying to refresh the page?
When the key is generated it doesn't update on the current view of the users profile. I have the Profile -View.php if it's going to help?

I commented out the code that you said to try as it didn't work.

margarett

I don't really see how that can work...

You added the function at the end of the file but it's not called anywhere. So I'm even surprised how that *ever* generates a key

Anyway, the reason why you need to refresh the page to see it is because the user details are loaded, THEN (after) your function runs and a key is generated. But the user details are not refreshed again.
So you need to, after running the function, to update $context['member']['product_key']
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

General Xbox Gaming

Quote from: margarett on October 12, 2014, 04:45:12 PM
I don't really see how that can work...

You added the function at the end of the file but it's not called anywhere. So I'm even surprised how that *ever* generates a key

Anyway, the reason why you need to refresh the page to see it is because the user details are loaded, THEN (after) your function runs and a key is generated. But the user details are not refreshed again.
So you need to, after running the function, to update $context['member']['product_key']
The function runs regardless I think so would cause a new key generation even if the user has a product_key already. That's why I tried to use it after the database is updated. Where is the area where the information is generated and I will add this before that else would this work if I put it in Profile.template.php where it displays to the user via echo.

Advertisement: