Home > Archive > PHP SQL > November 2004 > Link Query Results to a Webpage? (newbie question)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Link Query Results to a Webpage? (newbie question)
|
|
|
| I am trying to link the results from a query to a webpage. For exampe:
Results Below:
5432 Brookwood Drive 704-434-7532 www.greatparks.com
3221 Farmfield Drive 704-656-0234 www.allyoucanbe.com
1212 Dalton Rd. 704-323-9999 www.beagoodscout.com
I need a simple PHP script that will allow the user to click on the webpage
link. I would appreciate anyone that can help me. Thanks.
Rudy
| |
| Andy Hassall 2004-11-16, 6:53 pm |
| On Tue, 16 Nov 2004 16:59:06 -0500, "Rudy" <bre@bellsouth.net> wrote:
>I am trying to link the results from a query to a webpage. For exampe:
>
>Results Below:
>
>5432 Brookwood Drive 704-434-7532 www.greatparks.com
>3221 Farmfield Drive 704-656-0234 www.allyoucanbe.com
>1212 Dalton Rd. 704-323-9999 www.beagoodscout.com
>
>I need a simple PHP script that will allow the user to click on the webpage
>link. I would appreciate anyone that can help me. Thanks.
That's just a matter of putting an <a> tag around the address, surely?
i.e. instead of
print $row['url'];
Then:
sprintf("<a href='http://%s'>%s</a>",
htmlspecialchars($row['url']));
htmlspecialchars($row['url']));
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
| |
| Hilarion 2004-11-17, 8:56 am |
| > sprintf("<a href='http://%s'>%s</a>",
> htmlspecialchars($row['url']));
> htmlspecialchars($row['url']));
Shouldn't it be:
sprintf("<a href='http://%s'>%s</a>",
urlencode($row['url']),
htmlspecialchars($row['url'])
);
Hilarion
| |
| Andy Hassall 2004-11-17, 3:58 pm |
| On Wed, 17 Nov 2004 11:15:51 +0100, "Hilarion" <hilarion@SPAM.op.SMIECI.pl>
wrote:
>
>Shouldn't it be:
>
>sprintf("<a href='http://%s'>%s</a>",
> urlencode($row['url']),
> htmlspecialchars($row['url'])
> );
Actually that's what I typed first, then I had a think about it and went for
htmlspecialchars. Consider:
<?php
$row['url'] = 'localhost/test.php?blah=wurble+snurble';
printf("<a href='http://%s'>%s</a>",
urlencode($row['url']),
htmlspecialchars($row['url'])
);
?>
This doesn't do what's required; rather than outputting
<a href='http://localhost/test.php?blah=wurble+snurble'>
It outputs:
<a href='http://localhost%2Ftest.php%3Fblah%3Dwurble%2Bsnurble'>
Which isn't very useful. You don't want the / and ? encoded, you need them to
stay as literal characters because they're part of the URL.
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
| |
|
| Thanks ...that helps!
Rudy
"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:ka6np0hk9054aai3ortngqn5d5ihj1j9o7@
4ax.com...
> On Wed, 17 Nov 2004 11:15:51 +0100, "Hilarion"
<hilarion@SPAM.op.SMIECI.pl>
> wrote:
>
>
> Actually that's what I typed first, then I had a think about it and went
for
> htmlspecialchars. Consider:
>
> <?php
> $row['url'] = 'localhost/test.php?blah=wurble+snurble';
>
> printf("<a href='http://%s'>%s</a>",
> urlencode($row['url']),
> htmlspecialchars($row['url'])
> );
> ?>
>
> This doesn't do what's required; rather than outputting
>
> <a href='http://localhost/test.php?blah=wurble+snurble'>
>
> It outputs:
>
> <a href='http://localhost%2Ftest.php%3Fblah%3Dwurble%2Bsnurble'>
>
> Which isn't very useful. You don't want the / and ? encoded, you need
them to
> stay as literal characters because they're part of the URL.
>
> --
> Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
| |
| Hilarion 2004-11-18, 8:57 am |
| You are absolutely right about "urlencode" vs "htmlspecialchars". My mistake. Thanx for clarification.
Of course data in DB should be allready properly urlencoded which means that not using any
function in "href" value is an option too (but it's better to use "htmlspecialchars" in case of typos
and other mistakes).
You made some typos in your code ( ");" instead of just "," in second line ), but they are irrelevant.
Hilarion
|
|
|
|
|