Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default Variables in functions?

    If i had a function

    PHP Code:
    function tom() {
        if ( 
    $_GET['name'] == "Tom" ) {
            
    $var "Tom";
        }
        else {
        
    $var "Your name is not Tom";
        }

    Can i echo the var out side of the function, becuase at the moment im having trouble doing it, but im not sure if its a problem with my sql code or that lol.
    Lets set the stage on fire, and hollywood will be jealous.

  2. #2

    Default

    PHP Code:
    function tom() {
        if ( 
    $_GET['name'] == "Tom" ) {
            
    $var "Tom";
        }
        else {
        
    $var "Your name is not Tom";
        }
    return 
    $var;

    That might work? When you want to show the variable, just call the function..

  3. #3
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    PHP Code:
    function foo ()
    {
        
    $name $_GET["name"];
        if ( 
    $name == "Tom" ) {
            
    $variable $name;
        }
        else {
            
    $variable "Hey! Your name is not Tom!";
        }
        return 
    $variable;
    }

    $returnVar foo();

    echo 
    $returnVar

  4. #4
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    PHP Code:
    function foo ()
    {
        
    $name $_GET["name"];
        if ( 
    $name == "Tom" ) {
            
    $variable $name;
        }
        else {
            
    $variable "Hey! Your name is not Tom!";
        }
        return 
    $variable;
    }

    $returnVar foo();

    echo 
    $returnVar
    Hmm its still not working, maybe its a problem with my sql.

    im using the function to set the sql code;

    PHP Code:
    function sqlby($cat) {
        if ( 
    $_GET['order'] == "desc" ) {
            echo 
    "selected";
            if ( 
    $cat == "all" ) {
                
    $query ="SELECT * FROM games ORDER BY `games`.`dateday` DESC, `datemonth` DESC , `dateyear` DESC LIMIT " $pagedatastart " , " $pagedataend;
            }
            else {
                
    $query "SELECT * FROM games WHERE cat = '" $cat "' ORDER BY `games`.`dateday` DESC, `datemonth` DESC , `dateyear` DESC LIMIT " $pagedatastart " , " $pagedataend;
            }
        }
        if ( 
    $_GET['order'] == "asc" ) {
            echo 
    "selected";
            if ( 
    $cat == "all" ) {
                
    $query "SELECT * FROM games ORDER BY `games`.`dateday` ASC, `datemonth` ASC , `dateyear` ASC LIMIT " $pagedatastart " , " $pagedataend;
            }
            else {
                
    $query "SELECT * FROM games WHERE cat = '" $cat "' ORDER BY `games`.`dateday` ASC, `datemonth` ASC , `dateyear` ASC LIMIT " $pagedatastart " , " $pagedataend;
            }
        }
    return 
    $query;

    then im using this to get the $query
    PHP Code:
            $query sqlby("action");
            
    mysql_query($query) or die(mysql_error()); 
    And i get this mysql error;

    Query was empty

    +rep if anyone knows whats wrong with it.
    Lets set the stage on fire, and hollywood will be jealous.

  5. #5
    Join Date
    Dec 2007
    Posts
    1,683
    Tokens
    0

    Latest Awards:

    Default

    I can't remember if you need to connect functions to the db, try that.

  6. #6
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Do you have desc or asc in the URL? ?order=bla

  7. #7
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    Do you have desc or asc in the URL? ?order=bla
    LOL, thanks. That was the problem.

    I would give u a +rep but it says i need to spread.
    Lets set the stage on fire, and hollywood will be jealous.

Posting Permissions

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