Results 1 to 14 of 14

Thread: Output of $var problem...

  1. #1

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    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
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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',
                   
    => 'Noob');

    $highest_rank 0;

    foreach(
    $ranks as $count => $name) {
        if (
    $post_count >= (int) $count) {
            
    $highest_rank $count;
        }
    }

    echo(
    $ranks[$highest_count]); 
    Last edited by visualAd; Nov 25th, 2005 at 12:59 AM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    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]"]); 
    Last edited by PlaGuE; Nov 24th, 2005 at 05:00 PM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  5. #5
    Fanatic Member
    Join Date
    Oct 2004
    Posts
    751

    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]); ?
    My Projects: [ Instant Messagener Client/Server ] [ VBPictochat ]

    My Sites:
    [ Datanethost ]
    [ Helpdesk ]

    Remember if my post was helpful then Rate This Post.

  6. #6

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    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
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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'); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Output of $var problem...

    umm... call me a noob and slap my @$$..

    If the obvious is there... it sure is hiding well.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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

    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]); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    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.
    Last edited by PlaGuE; Nov 25th, 2005 at 10:46 AM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  11. #11
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Output of $var problem...

    You havn't put the numbers inside strings.
    Last edited by visualAd; Nov 25th, 2005 at 11:47 AM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Output of $var problem...

    Good point. By using integer indexes, the elements get re-ordered, I think.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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

    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    
    ?>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  14. #14

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    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.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width