Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post

    Question Return row from db

    i want to get a row from a mysql db with this code
    PHP Code:
    <?php
    mysql_pconnect
    """"""
                   or die( 
    "Unable to connect to SQL server"); 
    mysql_select_db"") or die( "Unable to select database"); 

    $Artist $_GET['Artist'];
    $Song $_GET['Song'];

    $result mysql_query('SELECT Lyric FROM Lyrics');
    if (!
    $result) {
       die(
    'Invalid query: ' mysql_error());
    }
    echo 
    'Artist:  ' $Artist '<br>';
    echo 
    'Song: ' $Song '<br>';
    echo 
    'Lyrics: ' $result '';

    ?>
    i know how to ge tthe artist and song, but i want to get the lyrics from my db by using the artist and the song.. my output for lyrics shows Lyrics: Resource id #2 right now..what does that mean and how do i fix it?

  • #2
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $row mysql_fetch_row($result); 
    Gives you an array with the contents of 1 row of the results. You are gunna need to put a WHERE clause in your select query to get the correct lyrics as well.
    Beauty is in the eye of the beer-holder

    Man who smoke pot, choke on handle

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    following your instructions to the best of my simple-minded abilities, this is what i have
    PHP Code:
     <?php
    mysql_pconnect
    """"""
                   or die( 
    "Unable to connect to SQL server"); 
    mysql_select_db"") or die( "Unable to select database"); 


    $Artist $_GET['Artist'];
    $Song $_GET['Song'];
    $Lyric $_GET['Lyric'];
    $result mysql_query('SELECT Lyric FROM Lyrics WHERE Song = ' $Song '');
    if (!
    $result) {
       die(
    'Invalid query: ' mysql_error());
    }
    $row mysql_fetch_row($result); 
    echo 
    'Artist:  ' $Artist '<br>';
    echo 
    'Song: ' $Song '<br>';
    echo 
    'Lyrics: ' $row '';

    ?>
    and this is what i get
    Invalid query: Unknown column 'the song name i typed in' in 'where clause'

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Is the first letter in your database table column name capitalized? Is it Lyric or is it lyric? First rule of programming, watch capitalization. Most programming languages are case sensitive as well as the Linux box which most sites are being run on. You might be used to capitalizing the first letters of words when you write letters to friends and family but this is not a letter this is programming. In programming there are fairly standard guidelines when it comes to using capital letters. Here's a great little article that discusses that:

    http://www.spelman.edu/~anderson/tea...sources/style/
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    it's capitlaized..if i changed it, would it fix someo f my problems?

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    make that ..

    PHP Code:
    <?
    $row 
    mysql_fetch_row($result);  
    echo 
    'Artist:  ' $Artist '<br>'
    echo 
    'Song: ' $Song '<br>'
    echo 
    'Lyrics: ' $row[0] . ''
    ?>
    though mysql_assoc() may be easier to use in the long run (if not in this particular case) , note how the $row is referenced above and below.

    PHP Code:
    <?
    $row 
    mysql_fetch_assoc($result);  
    echo 
    'Artist:  ' $Artist '<br>'
    echo 
    'Song: ' $Song '<br>'
    echo 
    'Lyrics: ' $row['Lyric'] . ''
    ?>
    if you had fetched all the data from the DB ..


    $result = mysql_query('SELECT Lyric,Artist,Song FROM Lyrics WHERE Song = ' . $Song . '');

    then you would have $row['Artist'] , $row['Song'] available as well
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #7
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    i hate to keep postin but im lost..ive tried all suggestions so far and this is my code now...
    PHP Code:
     <?php
    mysql_pconnect
    """"""
                   or die( 
    "Unable to connect to SQL server"); 
    mysql_select_db"") or die( "Unable to select database"); 


    $Artist $_GET['Artist'];
    $Song $_GET['Song'];
    $Lyric $_GET['Lyric'];
    $result mysql_query('SELECT Lyric FROM Lyrics WHERE Song = ' $Song '');
    if (!
    $result) {
       die(
    'Invalid query: ' mysql_error());
    }

    $row mysql_fetch_row($result);  
    echo 
    'Artist:  ' $Artist '<br>'
    echo 
    'Song: ' $Song '<br>'
    echo 
    'Lyrics: ' $row[0] . ''
    ?>
    and im still getting the same error as mention above in previous posts..believe me when i say i hate to keep bothering everyone because its not like i wanna sit here and try 50 million suggestions from everyon...but dont thake that the wrong way...if it wasnt for suggestions, i wouldn't know anything. So thanks for the help

  • #8
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    A good way to start debugging problems with database queries is to echo out the query. Usually it is a good idea to store your query in a variable like so. This makes debugging and such easier.

    PHP Code:
    $query "SELECT Lyric FROM Lyrics WHERE Song = " $Song;
    echo 
    $query
    echo out your query and see what it is being sent to mysql.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #9
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    well, that fixed one of my problems..letme restate this for better understanding of the situation or for more help... How would I fetch and echo out a row of information that is specified by a user
    Last edited by Meltdown; 06-09-2004 at 04:17 AM.

  • #10
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    well, could someone at least give me a script that does this..

  • #11
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Well your code is already set up to allow you to do that. You are using $Song as the variable for your where clause and that value is coming from the GET array which I assume you are pulling from a form filled out by the user.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #12
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    right...and the song and artist values work..i jsut cant get the lyrics to show up. the the song and artist are coming from variables in a url and i was wanting to fethc the lyrics using the song and artist

  • #13
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Well then you just need to add another condition to your where clause for the artist. WHERE Song = $Song AND Artist = $Artist
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #14
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    it gives me the same error as mentioned above
    Last edited by Meltdown; 06-09-2004 at 10:25 PM.

  • #15
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    I mentioned earlier that you should echo your query. What was the output of that?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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