-
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.
-
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"];
-
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.
-
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...
-
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.