Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP coding "global"

  • 16-11-2005 3: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,170 ✭✭✭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