/    Sign up×
Community /Pin to ProfileBookmark

access variables in another PHP script file

Hi,

Newbie question. Below is not exactly what I’m doing, but is similar.

I have an array of people names and other details (DOB, Sex, etc.). I’m displaying the names, and at the same time I want the names to be links which when clicked would run “Details.php” where all details are displayed for the name clicked.

[code=php]
for ($i=0; $i < $num_persons; $i++)
{
$person_name = $group_data[$i][1];
echo ‘name = ‘.'<a href=”Details.php”>’.$person_name.'</a><br />’;
}
[/code]

Question: how can I access the array $group_data in Details.php?

Thanks in advance

DL

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordJul 24.2008 — [code=php]
for ($i=0; $i < $num_persons; $i++)
{
$person_name = $group_data[$i][1];
echo 'name = '.'<a href="Details.php?pname=' . $person_name . '">'.$person_name.'</a><br />';
}
[/code]


as for details.php

[code=php]
$pname = $_REQUEST['pname'];

echo $pname;

// NOTE: Should validate this before using $pname in anything to avoid SQL Injection and other awful events
[/code]
Copy linkTweet thisAlerts:
@datalineauthorJul 24.2008 — Thanks for the help Phil.

Details.php displays the name fine. Now the question is how do I get Details.php to display the details for that person.
Copy linkTweet thisAlerts:
@Phill_PaffordJul 24.2008 — well there are a couple of ways, the most preferred way would be by object. if your going to pass by URL then you have to pass all of them or you could do another query from details.php but I think this is a waste of time.

if pass by object you will need to make a class that holds all the data in an object then include the access to the object to the details.php page and use the object values there.

a better understanding on objects:

http://us3.php.net/zend-engine-2.php

http://www.killerphp.com/videos/object-oriented-php-videos.php

also search for class

Hope this helps
Copy linkTweet thisAlerts:
@callumdJul 25.2008 — I'd advise against using $_REQUEST, you really should instead use $_GET.

$_REQUEST is considered to be less secure.
Copy linkTweet thisAlerts:
@datalineauthorJul 28.2008 — Phill and callumd,

Thank you both for your help!

I tried $_REQUEST and $_GET, and both work equally well. Being a newbie, I will take callumd's words and use $_GET.

Phill, I took a look at the 2 links you provided on objects in PHP5. I'm still running PHP4. So, I will skip this for now until I upgrade. What I will do for my issue is run the query in "details.php". As you said, this is a waste of time (hitting the database when the data is already available). Right now, my immediate objective is to get the code working. When I get to that, then I will look into improving efficiency (including upgrade to PHP5 and use objects, data validation to prevent SQL injection - another one of your suggestions, etc.)

Again thank you both!

DL
×

Success!

Help @dataline spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...