Jump to content

If value is artist display title(s)


Boxerman

Recommended Posts

Hi guys,

 

I'm pretty much stuck and require someones help,

 

I've got this script:

 

<?PHP
$con = mysql_connect("localhost","****","*****");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  
mysql_select_db("samdb", $con);

/* check to see if an artist has been selected */
if(!$_GET['artist']) {
$artist = 0;
}else{
$artist = $_GET['artist'];
}

/* if artist is set display the artist */
if($artist>0) {
$query = "SELECT * FROM songlist WHERE artist='$artist' ORDER BY id DESC";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$artist = $row['artist'];
$song = $row['title'];
?><p>
<b><font size="5"><?PHP echo $artist; ?></font> </b><br />
Songs: <?PHP echo $song; ?></p>
<br>
<br>
<a href="artist.php">Back to artist listings</a>
<?PHP
}else{
/* create query */
$query = "SELECT * FROM songlist GROUP BY artist ORDER BY artist DESC LIMIT 10";
/* execute the query */
$result = mysql_query($query);
while($row=mysql_fetch_array($result)) {
$artist = $row['artist'];
$song = $row['title'];
?><p>
<b><font size="5"><?PHP echo $artist; ?></font></b> <br>
<a href="artist.php?artist=<?PHP echo $row['artist']; ?>">See more</a></p>
<?PHP
} }
?>

 

It lists the artist right and thats great, however when i click on a artist's name it shows the same page does not go anywhere?

I've tired everything, it might be so simple its infront of me.. any help will be great!

 

Thanks

J

Link to comment
https://forums.phpfreaks.com/topic/260382-if-value-is-artist-display-titles/
Share on other sites

is the value for artist sent in the link here actually a number?

<a href="artist.php?artist=<?PHP echo $row['artist']; ?>">

I see you use the same part row here for the artist name

<b><font size="5"><?PHP echo $artist; ?></font></b> <br>

so if the value are sending is not a number this will fail

if($artist>0) {

 

remove this bit

/* check to see if an artist has been selected */
if(!$_GET['artist']) {
$artist = 0;
}else{
$artist = $_GET['artist'];
}

and change your if($artist>0) { to

if(isset($_GET['artist']) && $_GET['artist'] != '') {
  $artist = mysql_real_escape_string($_GET['artist']);

//rest of your code here

 

I am still getting the same issue :(

 

<?PHP
$con = mysql_connect("localhost","****","***");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  
mysql_select_db("samdb", $con);

/* check to see if an artist has been selected */
if(isset($_GET['artist']) && $_GET['artist'] != '') {
  $artist = mysql_real_escape_string($_GET['artist']);
}
/* if artist is set display the artist */
if($artist="") {
$query = "SELECT * FROM songlist WHERE artist='$artist'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$artist = $row['artist'];
$song = $row['title'];
?><p>
<b><font size="5"><?PHP echo $artist; ?></font> </b><br />
Songs: <?PHP echo $song; ?></p>
<br>
<br>
<a href="artist.php">Back to artist listings</a>
<?PHP
}else{
/* create query */
$query = "SELECT * FROM songlist GROUP BY artist ORDER BY artist DESC LIMIT 10";
/* execute the query */
$result = mysql_query($query);
while($row=mysql_fetch_array($result)) {
$artist = $row['artist'];
$song = $row['title'];
?><p>
<b><font size="5"><?PHP echo $artist; ?></font></b> <br>
<a href="artist.php?artist=<?PHP echo $row['artist']; ?>">See more</a></p>
<?PHP
} } 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.