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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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. |