/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] using mysql data as a link

I have the following

[code=php]
$row[‘web_address’];
[/code]

which has for example ‘www.webdeveloper.com’ stored there as a varchar

how can i echo this address on my page but allow it to be a clickable link??

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 24.2008 — The exact same way you would any other link: use an <a> HTML tag and put the address in the value for the "href" attribute of the tag.
Copy linkTweet thisAlerts:
@skibumauthorNov 24.2008 — That is what I though though I get a parse error when doing it that way I thought

which is
[code=php]
echo "<a href='http://$row['web_address']'>$row['web_address']</a>";
[/code]

what am i doing wrong?

Thanks
Copy linkTweet thisAlerts:
@MindzaiNov 24.2008 — That is what I though though I get a parse error when doing it that way I thought

which is
[code=php]
echo "<a href='http://$row['web_address']'>$row['web_address']</a>";
[/code]

what am i doing wrong?

Thanks[/QUOTE]


Try this:

[code=php]
echo '<a href="http://' . $row['web_address'] . '">' . $row['web_address'] . '</a>';
[/code]
Copy linkTweet thisAlerts:
@skibumauthorNov 24.2008 — When i tried that. it worked all except it added a '&#37;20' to the address like this

http://%20www.webdeveloper.com/

in the address bar
Copy linkTweet thisAlerts:
@MindzaiNov 24.2008 — You probably have a space inserted along with the web address in your database. Try this:

[code=php]
$address = trim($row['web_address']);
echo "<a href="http://$address">$address</a>";
[/code]


This sort of cleaning of data should really be done before inserting though so you might need to adjust your insert scripts.
Copy linkTweet thisAlerts:
@skibumauthorNov 24.2008 — That worked perfectly Thank you so much!
×

Success!

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