SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    links like lyrics.php?id=Song&1&Lyrics

    how would u make one page

    lyrics.php

    but iff a user clicked the link 'Song 1 Lyrics'

    Song 1 Lyrics
    Song 2 Lyrics
    Song 3 Lyrics

    i would want it to open
    lyrics.php
    but get the Song 1 lyrics Automatically So I Dont Have to Make Each Page By hand.

    so a link like lyrics.php?id=Song&1&Lyrics

    anyone shed some light?

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.
    I'm not sure if totally understand you question. You don't give much information about how you want it to work.

    Anyway, here is what I've come up with based on what you said. I'm assuming you're getting the lyrics from a database.
    PHP Code:
    // lyrics.php
    error_reporting(E_ALL);
    // All songs kept in an array
    $songs = array('Song 1 Lyrics''Song 2 Lyrics''Song 3 Lyrics');

    // Printing out a link for every song
    foreach($songs AS $song) {
        echo 
    '<a href="' $_SERVER['PHP_SELF'] . '?id=' urlencode($song) . '">Song 1 Lyrics</a><br />';
    }

    // Getting the lyrics for a song based on what link is clicked.
    if(isset($_GET['id']) && in_array($_GET['id'], $songs)) {
        
    $id urldecode($_GET['id']);
        
    $query "SELECT lyrics FROM table WHERE id=$id";
        
    // query db and view result

    HTH

    -Helge

  3. #3
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks ill have a try when i finish this script im doin ;P

  4. #4
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your script is working nearly
    im just wondering how to out put the lyrics
    on the page i want.

    i tried this but dosnt seem to work

    PHP Code:
    <?php 

    if(isset($_GET['song']) && in_array($_GET['song'], $songs)) { 
         
    $song urldecode($_GET['song']); 

    $query "SELECT lyrics FROM audio WHERE song='$song'"
    $result mysql_query($query); 
    $numofrows mysql_num_rows($result); 

    while(
    $row mysql_fetch_array($result)) { 
    print

        <tr> 
        <td class="mainindex">'
    .$row["lyrics"].'</td> 
        </tr>'



    ?>

  5. #5
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Try
    PHP Code:
    if(isset($_GET['song']) && in_array($_GET['song'], $songs)) { 
          
        
    $song urldecode($_GET['song']); 

        
    $query "SELECT lyrics FROM audio WHERE song='$song'"
        
    $result mysql_query($query) or die(mysql_error()); 
        
    $numofrows mysql_num_rows($result) or die(mysql_error()); 

        if(
    $numofrows 0) {
            while(
    $row mysql_fetch_array($result)) { 
                print 
    '<tr><td class="mainindex">';
                print 
    $row['lyrics'];
                print 
    '</td></tr>'
            }
        } else {
            print 
    'No lyrics found.';
        }

    and see if you get any error messages.
    HTH

    -Helge

  6. #6
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    get no error messages at all, but still nothingworks.

    if u wanna see yourself

    http://www.zenolith.co.uk/audio.php

    only crimson ghosti s the song with lyrics in the db so far. try it

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.
    I get this errormessage from you site
    Warning: Wrong datatype for second argument in call to in_array in /home/virtual/site21/fst/var/www/html/lyrics.php on line 20
    Don't know if this is inportant though.

    You have the 'id' in your url (http://www.zenolith.co.uk/lyrics.php?id=Crimson+Ghost) but you use $_GET['song'] in your script. You need to be consistent. Use either id or song.

    -Helge

  8. #8
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    $query 
    "SELECT * FROM audio ORDER BY type DESC LIMIT 0,50";
    $result mysql_query($query);
    $numofrows mysql_num_rows($result);

    while(
    $row mysql_fetch_array($result)) {

    print
    '
        <tr>
        <td class="sched" align="center"> : </td>
        <td class="mainindex" align="center">'
    .$row["song"].'</td>
        <td class="mainindex" align="center">'
    .$row["type"].'</td>';

    $songs = array("".$row['song']."");

    foreach(
    $songs AS $song) { 

    print
    '
        <td class="mainindex" align="center"><a href="lyrics.php?song='
    .urlencode($song).'">Lyrics</a></td> 
        </tr>'
    ;
    }
    }
    ?>
    THAT IS THE audio.php page

    PHP Code:
    <?php

    if(isset($_GET['song']) && in_array($_GET['song'], $song)) { 
           
    $id urldecode($_GET['song']); 

    $query = ("SELECT lyrics FROM audio WHERE id='$id'") or die(mysql_error()); 
    $result mysql_query($query); 
    $numofrows mysql_num_rows($result); 

    if(
    $numofrows 0) { 

    while(
    $row mysql_fetch_array($result)) { 
    print 
    '
        <tr>
        <td class="mainindex">'
    .$row["lyrics"].'</td>
        </tr>'

            

    } else { 
    print 
    'No lyrics found.'

    }
    ?>
    can u tell me what to change here ?

  9. #9
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yay nm it works now thanks helge


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •