/    Sign up×
Community /Pin to ProfileBookmark

Clickable link displayed from within PHP Switch-Case structure?

I have learned very little php at this point.

I am using a prebuilt user login structure.

Based upon which authenticated user we have, I wish to be able to give them a clickable link to go to another page that is specific to them.

The following example shows only one Case, but I am contemplating between five to 20.

Instead of automatically sending this specific user to Google I would want a link to appear on the page this is on that could be clicked to send them to something like “joespage.html” on the server.

[CODE] <?php
switch ($User->getColumnVal(“User_FName”)) {
Case “Joe’s”:
header(“Location: http://www.google.com”);
break;
}
?>[/CODE]

Would one of you kind folks that knows what you are doing (as opposed to me, as this is a heck of a lot of trial and error here, and mostly error!) show me how this is properly done?

THANK-YOU!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 29.2015 — I would put the names and links into a data structure of some sort, and use that. It could be a database (recommended if it could be a lot of links or something you want to create dynamically via an admin panel or such), or simply an array:
[code=php]
$links = array(
'Manny' => 'http://example.com/foo.php',
'Moe' => 'https://example.net/index.html',
'Jack' => 'http://example.org/bar.php'
);
if(isset($links[$User->getColumnVal('User_FName')]) {
header('Location: '.$links[$User->getColumnVal('User_FName')]);
}
else {
// whatever you want to do if it doesn't match
}
[/code]
Copy linkTweet thisAlerts:
@brucemc777authorNov 29.2015 — Thank-you!
Copy linkTweet thisAlerts:
@brucemc777authorNov 29.2015 — I took the idea of storing the page in the database to heart and created the field in the same table that has User_Fname in it named User_Page. This is a much more efficient approach than I was taking before; I appreciate the shove in that direction. Now my only problem is how to create a clickable link that will use that field from the database as the target. Can you assist?

Best regards, and thank-you!
Copy linkTweet thisAlerts:
@NogDogNov 29.2015 — Just echo out the desired HTML, e.g. (for this hypothetical example we'll use "name" and "link" as the two column names of interest, and assume we got them from a DB query from which we then fetched the result into $row):
[code=php]
echo "<a href='{$row['link']}'>{$row['name']}'s page</a>";
[/code]
×

Success!

Help @brucemc777 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.23,
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,
)...