/    Sign up×
Community /Pin to ProfileBookmark

Can you use a foreach loop in header(‘Location:?

I’m trying to use a foreach loop in a header(‘Location: .. type script. Is there any way to do this?

I need to hold both the key and value variables in 2 of my sql calls. If anyone has a solution to this, that would be great.

[code=php]header(‘Location: ../checkout/cart/add?product=’.$id.’&qty=1&options[‘ . $dropdown_id . ‘] = ‘ . $dropdown_selection_id
foreach($options_array as $key => $value)
{
echo ‘&options[‘ . $key . ‘]=’ . $value;
}
);[/code]

This gives me a syntax error as you would imagine.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiAug 05.2010 — [code=php]
$location = "../checkout/cart/add?product=$id&qty=1&options[$dropdown_id]=$dropdown_selection_id";
foreach($options_array as $key => $value) {
$location .= "&options[$key]=$value";
}
header("Location: $location");
exit;[/code]


Don't forget to urlencode those variables too if necessary.
Copy linkTweet thisAlerts:
@smohauthorAug 06.2010 — THank you!!! Works like a charm!
×

Success!

Help @smoh 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.28,
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,
)...