Hydrian

11-09-2012, 11:21 PM

Hi, ive been working on a leveling system for my class, but im at the point where i need to make it automatic, so when a button is clicked add 5xp to the total xp.

Here is my code for the system

<?php

$array = array(

array(

'xp_required' => 150,

'level' => 1

),

array(

'xp_required' => 225,

'level' => 2

),

array(

'xp_required' => 337,

'level' => 3

),

array(

'xp_required' => 566,

'level' => 4

),

array(

'xp_required' => 846,

'level' => 5

),

array(

'xp_required' => 1274,

'level' => 6

),

array(

'xp_required' => 1911,

'level' => 7

),

array(

'xp_required' => 2866,

'level' => 8

),

array(

'xp_required' => 4299,

'level' => 9

),

array(

'xp_required' => 6449,

'level' => 10

)

);

$current_xp = 155;

foreach( $array as $reqs ){

if( $current_xp > $reqs['xp_required'] ){

$level = $reqs['level'];

}

}

echo 'You are at ' ,$level;

?>

http://pastebin.com/vTriKTkG

Please tell me how to do this.

Here is my code for the system

<?php

$array = array(

array(

'xp_required' => 150,

'level' => 1

),

array(

'xp_required' => 225,

'level' => 2

),

array(

'xp_required' => 337,

'level' => 3

),

array(

'xp_required' => 566,

'level' => 4

),

array(

'xp_required' => 846,

'level' => 5

),

array(

'xp_required' => 1274,

'level' => 6

),

array(

'xp_required' => 1911,

'level' => 7

),

array(

'xp_required' => 2866,

'level' => 8

),

array(

'xp_required' => 4299,

'level' => 9

),

array(

'xp_required' => 6449,

'level' => 10

)

);

$current_xp = 155;

foreach( $array as $reqs ){

if( $current_xp > $reqs['xp_required'] ){

$level = $reqs['level'];

}

}

echo 'You are at ' ,$level;

?>

http://pastebin.com/vTriKTkG

Please tell me how to do this.