SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: php/mysql help

Hybrid View

  1. #1
    SitePoint Enthusiast raynebair's Avatar
    Join Date
    Dec 2000
    Location
    Alabama
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need some help. I'm pulling data from my database into a file and creating links from that data to another page. What I want to do is use the variable I'm passing to query the database for the field I will use as the title of the page. I can't seem to get it to work.

    My link is this: song.php?artist=3

    then in the song.php I want to query the database with the artist variable and pull the artist name for the title of the page.

    It is printing all the tags that it should but it isn't printing the actual field. I also have another query further down the page that works fine.

    Can anyone make any suggestions on how to get the info I need? I'm only pulling one record with one field in the first query...the artist's name based on the artist #.

    My select is: Select Name from artists where ID = $artist
    I'm not sure the rest of my php code is correct though for pulling out the field from the result set.

    Thanks in advance for any help you can give.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We will most likely need to see the code that you are using.

    BUt I suspect you aren't parsing the result set correctly,

    You need to do something like this
    $result = mysql_query("Select Name from artists where ID = $artist");
    $row = mysql_fetch_array($result);
    $title = $row["name"];
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast raynebair's Avatar
    Join Date
    Dec 2000
    Location
    Alabama
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!

    Here is my code:

    <?
    mysql_connect(localhost, username, password);
    $result = mysql_query("Select Name from artists where ID = $artist");
    $row = mysql_fetch_array($result);
    $title = $row["Name"];
    ?>
    <head>
    <title><? echo $title ?></title>
    <? require('header.php'); ?>
    <strong><? echo $title ?></strong>

    I keep getting the Warning: Supplied argument is not a valid MySQL result resource in songs.php on line 6 which is the line with the fetch_array in it.

    What could be causing this? I copied this code from the message above.


  4. #4
    SitePoint Enthusiast JohnM's Avatar
    Join Date
    Dec 2000
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    Code:
    <? 
    mysql_connect(localhost, username, password); 
    $result = mysql_query("Select Name from artists where ID = $artist") or die("There was a problem: ".mysql_error());
    $row = mysql_fetch_array($result); 
    $title = $row["Name"]; 
    ?> 
    <head> 
    <title><? echo $title ?></title> 
    <? require('header.php'); ?> 
    <strong><? echo $title ?></strong>
    that should give you an error message telling what the problem is...

  5. #5
    SitePoint Enthusiast raynebair's Avatar
    Join Date
    Dec 2000
    Location
    Alabama
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks JohnM...that helped. I was able to fix the problem and now it is working!

    This forum is very helpful for us that are just starting out with php/mysql. I appreciate all the help everyone has given me. I know I will be back for more help as I develop my site.


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
  •