views:

300

answers:

4

I have a form that has a drop down list of song titles. I want to be able to click on one of the song titles and the lyrics be loaded on the same page. The lyrics are contained within .txt files in a folder called "Lyrics".

Example:

Drop down list contains: Song1 Song2 Song3 etc.

When the user clicks on the song, the contents of the corresponding .txt file are displayed on that same page. Any ideas?

A: 

This is quick solution, but highly insecure, use it only as example, how could be done, but shouldn't:

<?

// your page code here // this is body where you want to put song lyrics

file_get_contents($_GET['songName'].".txt")

// else..

?>

in meniu:

<a href="songs.php?songName=song1">song1</a>
lfx
If it shouldn't be done that way, don't suggest it
Ben James
It just example how could be done.
lfx
A: 
<?php
    $song = intval( $_GET[ 'song_id' ] );
    $songs = array( 0 => NULL, 1 => 'Song1', 2 => 'Song2', 3 => 'Song3' );
    echo file_get_contents( $songs[ $song ] . '.txt' );
?>

Good Luck!

Jacob Relkin
+1  A: 

It would be easier using JQuery:

<a href="somefile.txt" class="link">Song 1</a>
<pre id="lyrics">
</pre>

<script>
$(function(){
   $('.link').click(function(){
     $.get(this.href,null,function(lyrics){
         $('#lyrics').html(lyrics);
         return false;
     });
   });
});
</script>
jerjer
Good comment. Although he is asking for it in PHP.
Jacob Relkin
A: 
Cups