View Full Version : small help
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 >=
Didnt work, now doesnt display anything..
<?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
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]
?
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";
<?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.
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...
:|
<?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);
<?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?
where does the $points variable come from?
No where...
No where...
So why are they there ...
Do you actually know php?
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!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.