Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP coding "global"

  • 16-11-2005 03:17PM
    #1
    Registered Users, Registered Users 2 Posts: 673 ✭✭✭


    Hey,

    I'm learning PHP from a book at the moment and am stuck with this bit of code:

    //create function to get lead actor
    function get_leadactor($lead_actor) {
    global $actorname;
    $query2="SELECT people_fullname
    FROM people
    WHERE people.people_id = $lead_actor";
    $results=mysql_query($query2) or
    die(mysql error());
    $rows=mysql_fetch_array($results);
    extract ($rows);
    $actorname=$people_fullname;
    }


    I know that you are creating a function called "get_leadactor" and that it value will be stored in the variable "$lead_actor". What does "global $actorname;" do on the second line though?????

    I've been doing searched for "global" on the internet but i just keep on getting the same info about turning regictered_globals on/off in the php.ini file, but nothing telling me what this line of code is doing.

    Thanks for your help!!


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    basically it is setting a global variable called $actorname

    And this $actorname get its value from $people_fullname


  • Registered Users, Registered Users 2 Posts: 2,206 ✭✭✭Serbian


    Global is setting the scope of the variable. You can read more about Variable Scope in the PHP Manual.


  • Registered Users, Registered Users 2 Posts: 673 ✭✭✭Bananna man


    Thanks :) back on track now.


Advertisement