Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Using Return

  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    96
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Using Return

    Hey,
    Using return in a function will only execute it once, correct?
    After it's executed, it will end and won't do it again (Say if you have a while loop)

    What I want, is it to return and return the code ever how many times it needs to loop (For loop)
    Which is impossible using return.

    What I'd like to know, is if there is something very very similar to return that will do that, or another way.
    Here's what I have:

    PHP Code:
    class Features
    {
        function 
    stars($id//Usergroup stars
        
    {
            global 
    $queries;
            
    $usergroups $queries->groupQuery("`id`='$id'");
            
    $usergroup mysql_fetch_array($usergroups);
            
    //Value
            
    for ($stars 1$stars <= $usergroup['stars']; $stars++)
            {
                
    $star "<img src='images/skins/default/stars/admin_star.png' alt='Star' />";
                return 
    $star;
            }
        }

    And now to call it,
    PHP Code:
    class Thread
    {
        function 
    threads()
        {
            
    $features->stars($userg['id']);
        }

    Thanks.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Do you only have "full stars", or do you have some "half stars"?

    I'm guessing you are displaying stars like a "rating" system?

    You'll need to build the <img> tags into one string ... like this:
    PHP Code:
    class Features
    {
        function 
    stars($id//Usergroup stars
        
    {
            global 
    $queries;
            
    $usergroups $queries->groupQuery("`id`='$id'");
            
    $usergroup mysql_fetch_array($usergroups);
            
    //Value
            
    for ($stars 1$stars <= $usergroup['stars']; $stars++)
            {
                
    $star .= "<img src='images/skins/default/stars/admin_star.png' alt='Star' />";
            }
            return 
    $star;
        }


  • Users who have thanked mlseim for this post:

    Crisp (01-06-2010)

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    96
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Works great.
    Only thing is it says:
    PHP Code:
    NoticeUndefined variablestar in X 
    Which I'd like to be taken away.
    I see the problem, but I don't know how to fix it.

    Do you know what I can do to fix it where it still works?
    Thanks. (Nice sig btw! )

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You need to set $star to null or an empty string just before you start your for loop. If you don't then the scope of $star is only local to the for loop and nothing else.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Crisp (01-06-2010)

  • #5
    New Coder
    Join Date
    Feb 2009
    Posts
    96
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Oh, ok, fixed.
    Thanks a lot guys.


  •  

    Posting Permissions

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