Output of $var problem...
okay i had made sumtin like this a long time ago... and it worked.
lost the file so i gotta do it again...
anyways i have this code which will go into a lil news script.:
PHP Code:
if($row['postcount'] >= '100'){ $usertitle = "noob2"; }
elseif($row['postcount'] >= '150'){ $usertitle = "noob3"; }
elseif($row['postcount'] >= '200'){ $usertitle = "noob4"; }
elseif($row['postcount'] >= '500'){ $usertitle = "noob5"; }
elseif($row['postcount'] >= '1000'){ $usertitle = "noob6"; }
elseif($row['postcount'] >= '1500'){ $usertitle = "noob7"; }
elseif($row['postcount'] >= '2000'){ $usertitle = "noob8"; }
elseif($row['postcount'] >= '2500'){ $usertitle = "noob9"; }
elseif($row['postcount'] >= '3000'){ $usertitle = "noob10"; }
else{ $usertitle = "noob"; }
so that if there postcount is greater then or equal to the #.. the $variable is changed.
for example
i have 500 posts.. yes im "noob2".
help me plz. thanks
Re: Output of $var problem...
Every post count that's greater than 3500 is also greater than 100. Since 100 comes first, it will always succeed and grab all later cases. You need to flip them around and start with the largest.
Oh, and this should go into the PHP forum.
Re: Output of $var problem...
If I were you I would use an array to store post counts and the name of the rank associated with the post count. It is then a lot easier to add new ones:
PHP Code:
$ranks = array(3000 => 'Power Poster',
2000 => 'Addicted',
1000 => 'Hyper',
500 => 'Lively',
100 => 'Member',
0 => 'Noob');
$highest_rank = 0;
foreach($ranks as $count => $name) {
if ($post_count >= (int) $count) {
$highest_rank = $count;
}
}
echo($ranks[$highest_count]);
Re: Output of $var problem...
Thanks.
I was thining of doing an array... but just kept forgetting the idea.
BTW... I thought i posted it in the PHP section.
~~~~~~~~~~~~
okay edit.
Ummm... this is prolly the "just woke up and im still tired and cant think" moment right now... but ... what am i doing wrong... im with 500 posts and another is with 4...
yet im lively and hes nuthin....
i modified the code like so...
plz tell me what im doing wrong.
PHP Code:
$ranks = array(3000 => 'Power Poster',
2000 => 'Addicted',
1000 => 'Hyper',
500 => 'Lively',
100 => 'Member',
0 => 'Noob');
$highest_rank = 0;
foreach($ranks as $count => $name) {
if ($row['postcount'] >= (int) $count) {
$highest_rank = $count;
}
}
echo($ranks["$row[postcount]"]);
Re: Output of $var problem...
Get rid of the " in
echo($ranks["$row[postcount]"]);
But I don't think thats what you want still...
maybe echo($ranks[$highest_rank]); ?
Re: Output of $var problem...
with it
echo($ranks["$row[postcount]"]);
it echoed me as
lively
and him as (blank null nil nada neit no)
yet with
echo($ranks[$highest_rank]);
we all noobs... HEHE
Re: Output of $var problem...
I have a feeling you might need to make all the indexes text, indexes:
PHP Code:
$ranks = array('3000' => 'Power Poster',
'2000' => 'Addicted',
'1000' => 'Hyper',
'500' => 'Lively',
'100' => 'Member',
'0' => 'Noob');
Re: Output of $var problem...
umm... call me a noob and slap my @$$..
If the obvious is there... it sure is hiding well.
Re: Output of $var problem...
Quote:
Originally Posted by PlaGuE
umm... call me a noob and slap my @$$..
If the obvious is there... it sure is hiding well.
I am not sure what you are saying, so can I just slap you anyway :p
You just need to replace your array definition with this:
PHP Code:
$ranks = array('3000' => 'Power Poster',
'2000' => 'Addicted',
'1000' => 'Hyper',
'500' => 'Lively',
'100' => 'Member',
'0' => 'Noob');
$highest_rank = 0;
foreach($ranks as $count => $name) {
if ($post_count >= (int) $count) {
$highest_rank = $count;
}
}
echo($ranks[(string) $highest_count]);
Re: Output of $var problem...
hmm...
i tried... many different variations to that...
PHP Code:
$ranks = array(
3000 => 'Power Poster',
2000 => 'Addicted',
1000 => 'Hyper',
500 => 'Lively',
100 => 'Member',
0 => 'Noob'
);
$highest_rank = 0;
foreach($ranks as $count => $name) {
if ($row['postcount'] >= (int) $count) {
$highest_rank = $count;
}
}
echo($ranks[(string) $highest_count]);
but all it gives me is a "blank" space. for each the users.
Re: Output of $var problem...
You havn't put the numbers inside strings.
Re: Output of $var problem...
Good point. By using integer indexes, the elements get re-ordered, I think.
Re: Output of $var problem...
I must be loosing it this week. I forgot to test that the current count is not lower than the highest rnake already found :blush:
The code below should work, of course, you need to change the variable names to suit:
PHP Code:
<?php
$post_count = 999;
$ranks = array('3000' => 'Power Poster',
'2000' => 'Addicted',
'1000' => 'Hyper',
'500' => 'Lively',
'100' => 'Member',
'0' => 'Noob');
$highest_rank = 0;
foreach($ranks as $count => $name) {
if (($post_count >= ((int) $count)) && ($count >= $highest_rank)) {
$highest_rank = $count;
}
}
echo($ranks[(string) $highest_rank]);
// vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4
?>
Re: Output of $var problem...
hey... Its no biggie. we all have "bad" days.
but with me its more bad "months".
cuz ive been at this for a month and finally got fed up n posted about it.