Welcome Guest ( Log In | Register )



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Making Something In Mysql Happen Only Once
Feelay
post Feb 18 2008, 09:23 PM
Post #1


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



Hey! I know I am asking alot. But much is happening theese days.
Sorry if I disturb with my questions.

The thing I am trying to do is:
Ex. If the user becomes level 2, he should get 5 skill points. I can't do this:
CODE
if($userlevel=5){
mysql_query("UPDATE user SET skillpoints =$points+5");}

because then it would update everytime the code was loaded. I hope you understand what I am trying to do. If not, tell me smile.gif and i'll try to explain better.

Thanks //Feelay
Go to the top of the page
 
+Quote Post
PerHapsYouSeen
post Feb 19 2008, 04:41 AM
Post #2


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 23
Joined: 24-October 07
Member No.: 25,689



why dont't you add a column to store the last time he was got skill points. Isn't is much easier.

This post has been edited by PerHapsYouSeen: Feb 19 2008, 04:45 AM
Go to the top of the page
 
+Quote Post
mastercomputers
post Feb 19 2008, 08:23 AM
Post #3


PESTICIDAL MANIAC
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



Hey Feelay,

All I noticed is the common mistake with doing comparisons.

CODE
if($userlevel = 5)

is not the same as
CODE
if($userlevel == 5)


The first one is an assignment which means you'll make $userlevel become 5 and will result in true.

The second one will not solve the issue though, you really need to do something that PerhapsYouSeen has suggested and add a column to record that they have gotten their points, then you just need to check that first before you give them points.

Cheers,

MC

Go to the top of the page
 
+Quote Post
Feelay
post Feb 19 2008, 11:09 AM
Post #4


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



sorry tongue.gif but I don't understand tongue.gif
Go to the top of the page
 
+Quote Post
yordan
post Feb 19 2008, 01:29 PM
Post #5


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,042
Joined: 16-August 05
Member No.: 7,896



QUOTE(Feelay @ Feb 19 2008, 12:09 PM) *
sorry tongue.gif but I don't understand tongue.gif

He was explaining that your code does not test that the userlevel is 5.
Your code is forcing userlevel to be level 5, which is probably not what you want.
Go to the top of the page
 
+Quote Post
Feelay
post Feb 19 2008, 04:15 PM
Post #6


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



Oh. but my code was just an example.
I just wanted to show, that if I wrote that code, it would give the user 5 skill points every time the page was loaded. but I want it to give the user 5 skill points, only the moment the user reach level 5 (for ex.).

and between, I thougt of making a colum for the points, but the user will be able to "buy" health and strenght and stuff for theese points. so they (the points) will become 0 anyway =S

This post has been edited by Feelay: Feb 19 2008, 04:18 PM
Go to the top of the page
 
+Quote Post
pyost
post Feb 19 2008, 06:02 PM
Post #7


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,013
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



You have a script that increases a player's level if a condition is fulfilled, right? So why not just increase the points at the sime time you increase his/hers level?
Go to the top of the page
 
+Quote Post
Feelay
post Feb 19 2008, 08:10 PM
Post #8


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



because the script says:

If the user exp is more than 100, the user level should be changed to level 2 (etc.).. And that script runs everytime the user login. It would not work.
Go to the top of the page
 
+Quote Post
yordan
post Feb 19 2008, 10:01 PM
Post #9


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,042
Joined: 16-August 05
Member No.: 7,896



OK, it seems that you definitively need a user status column in a table. With a value like "3065" if the user is at level 3 and has 65 lifehalth points. Or value 4100 if level 4 with 100 points. You change this value only once (when he goes to level 5) and you read the value each time the player logs in.
Go to the top of the page
 
+Quote Post
pyost
post Feb 19 2008, 10:59 PM
Post #10


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,013
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



QUOTE(Feelay @ Feb 19 2008, 09:10 PM) *
because the script says:

If the user exp is more than 100, the user level should be changed to level 2 (etc.).. And that script runs everytime the user login. It would not work.


Why not "If the user exp is more than 100, the user level should be changed to level 2, and the user should get skill points (etc.).."?
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. MySQL & PHP coding(9)
  2. Need Help With A PHP - MySQL Registration Script(13)
  3. Need Some Help Using PHP & MySQL(4)
  4. [PHP + MySQL] Separating The Results By Pages(0)
  5. [PHP + MySQL] Encrypting Data(11)
  6. [php] Index.php?section=xx&pag=yy(6)
  7. How Do You Create A Secure Loging?(4)
  8. Important: Basics Of Using PHP And MySQL(10)
  9. Need Help With Php/mysql And Web Servers Such As Asta's.(4)
  10. Need MySQL Alternative To The Syntax "or die()"(8)
  11. Re-order MySQL Table(11)
  12. PHP & MySQL: Displaying Content From A Given ID(6)
  13. How To Show Serial Nums In PHP Table For Contents Of MySQL DB(4)
  14. Php Mysql Errors(2)
  15. Making My Album(3)
  1. Sql Injection Prevention (passing Numerical Data Across Pages).(9)
  2. Php/mysql And Manual Page Caching?(4)
  3. Too Many Connections?(4)
  4. Bbcode Help(9)
  5. Extracting Mysql Maths Using Php(2)
  6. Making Animated Gifs(5)
  7. Anyone Know Of A Really Good Mysql Class?(4)
  8. Warning: Mysql_num_rows()(1)
  9. Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...(4)
  10. Making A Link = Mysql_query(8)
  11. Mysql Question(inserting Number From A Textfield)(3)
  12. Making A Value In A Textbox Stay(4)
  13. Letting Users Add Mysql Data With Php(1)


 



- Lo-Fi Version Time is now: 11th October 2008 - 07:58 AM