Bluehost.com Web Hosting $6.95

Make query result into hyperlink.

This is a discussion on Make query result into hyperlink. within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello, I am sorry if this is a really simple stupid question but I spent hours yesterday trawling the net ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-02-2004
Richard
 
Posts: n/a
Default Make query result into hyperlink.

Hello,

I am sorry if this is a really simple stupid question but I spent hours
yesterday trawling the net trying to find an answer to no avail.
I have the following page that queries a mysql database and displays the
query in a table.

<?php
$link = mysql_connect("localhost", "user", "pass");
mysql_select_db("music");
$query = mysql_query("SELECT * FROM artist");
while (list($id, $artist, $num_plays, $last_play, $date_added, $filename) =
mysql_fetch_row($query)) {
echo
"<TR><TD><p>$id</TD><TD>$artist</TD><TD>$num_plays</TD><TD>$last_play</TD><T
D>$date_added</TD></p></TR>";
}
?>

I have the query collect the $filename variable which is the path to the mp3
file, what I would kike to do is turn each column returned by the query into
a hyperlink that would play the song.
I started to try something like this

echo "<A
HREF="$filename"><TR><TD><p>$id</TD><TD>$artist</TD><TD>$num_plays</TD><TD>$
last_play</TD><TD>$date_added</TD></p></TR></A>";

but the "" in the HREF statement conflict. I was playing around with the
exec
function but could not get it to work.
Could someone please point me in the right direction.
Also if any one could recommend a book or any resources for someone who
knows very little about programming and would like to know more about PHP
and Perl database integration I would be eternally grateful.

Thanks
Richard.








Reply With Quote
  #2 (permalink)  
Old 02-02-2004
Tim Van Wassenhove
 
Posts: n/a
Default Re: Make query result into hyperlink.

On 2004-02-02, Richard <rsadler@iiu.ie> wrote:
> echo "<A
> HREF="$filename"><TR><TD><p>$id</TD><TD>$artist</TD><TD>$num_plays</TD><TD>$
> last_play</TD><TD>$date_added</TD></p></TR></A>";


fe: echo "<a href='$filename'>...........";

http://www.php.net/manual -> variables -> strings

--
http://home.mysth.be/~timvw
Reply With Quote
  #3 (permalink)  
Old 02-02-2004
Louis M
 
Posts: n/a
Default Re: Make query result into hyperlink.

Richard wrote:
> Hello,
>
> I am sorry if this is a really simple stupid question but I spent hours
> yesterday trawling the net trying to find an answer to no avail.
> I have the following page that queries a mysql database and displays the
> query in a table.
>
> <?php
> $link = mysql_connect("localhost", "user", "pass");
> mysql_select_db("music");
> $query = mysql_query("SELECT * FROM artist");
> while (list($id, $artist, $num_plays, $last_play, $date_added, $filename) =
> mysql_fetch_row($query)) {
> echo
> "<TR><TD><p>$id</TD><TD>$artist</TD><TD>$num_plays</TD><TD>$last_play</TD><T
> D>$date_added</TD></p></TR>";
> }
> ?>
>
> I have the query collect the $filename variable which is the path to the mp3
> file, what I would kike to do is turn each column returned by the query into
> a hyperlink that would play the song.
> I started to try something like this
>
> echo "<A
> HREF="$filename"><TR><TD><p>$id</TD><TD>$artist</TD><TD>$num_plays</TD><TD>$
> last_play</TD><TD>$date_added</TD></p></TR></A>";
>
> but the "" in the HREF statement conflict. I was playing around with the
> exec
> function but could not get it to work.
> Could someone please point me in the right direction.
> Also if any one could recommend a book or any resources for someone who
> knows very little about programming and would like to know more about PHP
> and Perl database integration I would be eternally grateful.
>
> Thanks
> Richard.
>

You need to either escape your quote marks within your string:
echo "<A
HREF=\"$filename\"><TR><TD><p>$id</TD><TD>$artist</TD><TD>$num_plays</TD><TD>$
last_play</TD><TD>$date_added</TD></p></TR></A>";

Or use single quote marks, like this:

echo "<A
HREF='$filename'><TR><TD><p>$id</TD><TD>$artist</TD><TD>$num_plays</TD><TD>$
last_play</TD><TD>$date_added</TD></p></TR></A>";

Or this:

echo '<A
HREF="$filename"><TR><TD><p>$id</TD><TD>$artist</TD><TD>$num_plays</TD><TD>$
last_play</TD><TD>$date_added</TD></p></TR></A>';

If you use the "..." quote convention, you can also escape Backslash
(\\) Newline (\n) CariageReturn (\r) Tab (\t) and Hex chars (\xoo - \xFF).

Note, if your string uses single '...' quote marks the escape behaviour
will not work except for single quote itself (eg print 'batman\'s lair'
and your inline variables (ie $artist) will appear as '$artist', not as
the value it refers to.

Here endeth the lesson.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:15 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0