PDA

View Full Version : small help



Ini
03-01-2008, 05:07 PM
Yeh how can i get my points to display as levels

So if i want from 0 to 100 to be level 1

then from 100 to 200 to be level 2 etc

say all the way upto 900 to 1000 level 10

i have tried



if ($op[points] <0 && $op[points] >100) {
echo "Level 1";
} else {
if ($op[points] <100 && $op[points] >200) {
echo "Level 2";
}

etc..


But it only displays the levels when the points are either the first number or the last number

any help?

Moved by Agesilaus (Forum Moderator) from Designing and Development: Please post in the correct forum next time. :)

craigg.
03-01-2008, 05:09 PM
add an equals sign. So it is equal to or greater/less than. Eg >=

Ini
03-01-2008, 05:32 PM
Didnt work, now doesnt display anything..

Blob
03-01-2008, 06:11 PM
<?php
function sort_level( $start, $finish )
{
if( $op["points"] >= $start && $op["points"] <= $finish )
{
return true;
} else
{
return false;
}
}
$points['level']['1'] = sort_level(1, 100);
$points['level']['2'] = sort_level(101, 200);
$points['level']['3'] = sort_level(201, 300);
$points['level']['4'] = sort_level(301, 400);
for( $i = 0; $i < count($points['level']); $i++ )
{
if( $points['level'][$i] == true )
{
echo "Level " . $i;
}
}
?>


Should work.

I like to code over the top =D

Ini
03-01-2008, 06:31 PM
Hmm..

Doesnt work..

Maybe if i can update the $op[level] by adding to it

So how could i do it so

A user clicks 'add points'

then it updates the points in the db then changes the level

if it is over the max points for level 1 say

then it changes the level to 2?

Then i could just display the level

by using $op[level]

?

Blob
03-01-2008, 06:50 PM
Hmm..

Doesnt work..

Maybe if i can update the $op[level] by adding to it

So how could i do it so

A user clicks 'add points'

then it updates the points in the db then changes the level

if it is over the max points for level 1 say

then it changes the level to 2?

Then i could just display the level

by using $op[level]

?


<?php
function sort_level( $start, $finish )
{
global $op;
if( $op["points"] >= $start && $op["points"] <= $finish )
{
return "true";
} else
{
return "false";
}
}
$points['level']['1'] = sort_level(1, 100);
$points['level']['2'] = sort_level(101, 200);
$points['level']['3'] = sort_level(201, 300);
$points['level']['4'] = sort_level(301, 400);
for( $i = 0; $i < count($points['level']); $i++ )
{
if( $points['level'][$i] == "true" )
{
echo "Level " . $i;
}
}
?>

That works, ive tested it.

MrCraig
03-01-2008, 08:20 PM
if ($op[points] <0 && $op[points] >100) {
echo "Level 1";
} else {
if ($op[points] <100 && $op[points] >200) {
echo "Level 2";
}


How can your points be less than 0 and over 100 at the same time?

try..



if ($op[points] >0 && $op[points] <100) {
echo "Level 1";
}
elseif ($op[points] >100 && $op[points] <200)
echo "Level 2";
else
echo "Level 3";

Ini
03-01-2008, 08:24 PM
<?php
function sort_level( $start, $finish )
{
global $op;
if( $op["points"] >= $start && $op["points"] <= $finish )
{
return "true";
} else
{
return "false";
}
}
$points['level']['1'] = sort_level(1, 100);
$points['level']['2'] = sort_level(101, 200);
$points['level']['3'] = sort_level(201, 300);
$points['level']['4'] = sort_level(301, 400);
for( $i = 0; $i < count($points['level']); $i++ )
{
if( $points['level'][$i] == "true" )
{
echo "Level " . $i;
}
}
?>

That works, ive tested it.
Cant get it work won't display anything..

MrPinkPanther
03-01-2008, 08:28 PM
if ($op[points] <0 && $op[points] >100) {
echo "Level 1";
} else {
if ($op[points] <100 && $op[points] >200) {
echo "Level 2";
}


How can your points be less than 0 and over 100 at the same time?

try..



if ($op[points] >0 && $op[points] <100) {
echo "Level 1";
}
elseif ($op[points] >100 && $op[points] <200)
echo "Level 2";
else
echo "Level 3";

Listen to this dude Ryan. Your signs are all wrong.

Ini
03-01-2008, 10:49 PM
nope cant get it to work, ryan could you explain what values are which so i no what to edit..

MrCraig
04-01-2008, 03:27 PM
the one i posted works...

:|

Ini
04-01-2008, 04:52 PM
Didn't see yours..

Blob
04-01-2008, 04:57 PM
<?php
// DO NOT EDIT
function sort_level( $start, $finish )
{
global $op;
if( $op["points"] >= $start && $op["points"] <= $finish )
{
return "true";
} else
{
return "false";
}
}
// EDIT THIS BIT
$points['level']['1'] = sort_level(1, 100);
$points['level']['2'] = sort_level(101, 200);
$points['level']['3'] = sort_level(201, 300);
$points['level']['4'] = sort_level(301, 400);
// DO NOT EDIT
for( $i = 0; $i < count($points['level']); $i++ )
{
if( $points['level'][$i] == "true" )
{
echo "Level " . $i;
}
}
?>

Ok, to edit it, do this:


$points['level']['LEVEL IN HERE'] = sort_level(MIN POINTS TO GET LEVEL, MAX POINTS TO GET LEVEL);

Ini
04-01-2008, 05:07 PM
<?php
// DO NOT EDIT
function sort_level( $start, $finish )
{
global $op;
if( $op["points"] >= $start && $op["points"] <= $finish )
{
return "true";
} else
{
return "false";
}
}
// EDIT THIS BIT
$points['level']['1'] = sort_level(1, 100);
$points['level']['2'] = sort_level(101, 200);
$points['level']['3'] = sort_level(201, 300);
$points['level']['4'] = sort_level(301, 400);
// DO NOT EDIT
for( $i = 0; $i < count($points['level']); $i++ )
{
if( $points['level'][$i] == "true" )
{
echo "Level " . $i;
}
}
?>

Ok, to edit it, do this:


$points['level']['LEVEL IN HERE'] = sort_level(MIN POINTS TO GET LEVEL, MAX POINTS TO GET LEVEL);
where does the $points variable come from?

Blob
04-01-2008, 05:08 PM
where does the $points variable come from?

No where...

Ini
04-01-2008, 06:06 PM
No where...
So why are they there ...

Blob
04-01-2008, 07:20 PM
Do you actually know php?

Ini
04-01-2008, 07:32 PM
Yes..

but i dont understand this function..

Beucase it doesn't work for me and i cant understand why..?

MrCraig
04-01-2008, 08:33 PM
the $points variable is created to store the results of the function..

Want to hide these adverts? Register an account for free!