SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot thetzfreak's Avatar
    Join Date
    Aug 2004
    Location
    United States
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Making All Variables Automatically Global?

    Hi, I have a script that queries a database many times on one page, and each time the query information is the same, except for one WHERE something LIKE something statement. I want to create this function:

    PHP Code:
    function query($category) {$query "SELECT some_columns FROM business WHERE category like '$category' ORDER BY category ASC";
        
    $result mysql_query($query) or die(mysql_error()."<br />".$query);
        
    $num_results mysql_num_rows($result);} 
    Variables such as $num_results are not going to be able to be used (I don't think) outside this function. How do I automatically make all variables outside a function work inside a function, and all variables inside a function work outside the function? It would take me forever to make the variables I need global one by one.

    Thanks.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you want everything done within the global scope, maybe thats what you should do. just use an include file and include it into the global scope.


Bookmarks

Posting Permissions

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