Jump to content

Recommended Posts

I have created a Database driven CD Database, right now, I have adding cd to the db "name and title" after adding the cd you can now add the tracks, But after I add tracks... and click the link on the homepage it shows all tracks for all the cds...

My question is, How do I only see the tracks for the selected cd after the link is clicked?
Here is the code for the the link:
should be (cd_id and trigger and cd_title)
[code]
<a href='tracks.php?cd_id={$cd3['cd_id']}&tracks&cd_title={$cd3['cd_title']}'>Tracks</a>
[/code]

Here is the code for the tracks.php page:

[code]
<html>
<head>
<?php
include 'connect.php';
$cdl = @mysql_query("select * from cds where cd_id={$_GET['cd_id']}");
$cd2 = @mysql_num_rows($cdl);
$cd3 = @mysql_fetch_array($cdl);
?>
<title>Tracks for [<?php echo "{$cd3['cd_band']} - {$cd3['cd_title']}"; ?>]</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>

<body class="UsePageBg">
<a href="index.php">Home</a><br>
<?php
if (isset($tracks)):
?>

<table width="100%" border="1"  class="InternalHeader" >
  <tr>
    <td width="10%" align="center">CD Band</td>
    <td width="10%" align="center">CD Title&nbsp;</td>
    
  </tr>
</table>
<?php

// get cds
include 'connect.php';
$cdl = @mysql_query("select * from cds where cd_id={$_GET['cd_id']}");
$cd2 = @mysql_num_rows($cdl);
$cd3 = @mysql_fetch_array($cdl);

//get tracks
$cd4 = @mysql_query("select * from tracks where cd_id={$_GET['cd_id']}&cd_title={$_GET['cd_title']}");
$cd5 = @mysql_num_rows($cd4);
$cd6 = @mysql_fetch_array($cd4);
?>
<table width="100%" border="1" cellspacing="0" cellpadding="0" class="NormalTableTwo">
  <tr>
    <td width="10%" align="center"><?php echo "{$cd3['cd_band']}"; ?></td>
    <td width="10%" align="center"><?php echo "{$cd3['cd_title']}"; ?></td>
  </tr>
  
</table>
<p>
<a href="tracks.php?cd_id=<?php echo "{$cd3['cd_id']}"; ?>&addtracks&<?php echo "{$cd3['cd_title']}"; ?>">Add Tracks</a><br>
<table width="100%" border="1" class="InternalHeader">
  <tr>
    <td width="10%" align="center">CD Track No.</td>
    <td width="100%" align="center">CD Track Title&nbsp;</td>
    
  </tr>
</table>
<?php
include 'connect.php';
mysql_connect("$server", "$username", "$password") or die (mysql_error());
$result = mysql_db_query($db, "SELECT * FROM tracks order by cd_trackid") or die (mysql_error());

if (mysql_num_rows($result)) {
?>
<table width="100%" border="1" cellspacing="0" cellpadding="0" class="NormalTableTwo">
<?php
while ($qry = mysql_fetch_array($result)) {
echo "
  <tr>
    <td width='10%' align='center'>{$qry['cd_trackno']}</td>
    <td width='100%' align='center'>{$qry['cd_tracktitle']}</td>
    
  </tr>";
  }
  }
  ?>
</table>

<?php echo "{$cd3['cd_title']}"; ?>
</body>
</html>
<?php

  endif;
  ?>
<?php
if (isset($addtracks)):
include("connect.php");

//$cd_id = $_GET["cd_id"];
    //$r = @mysql_query("select * from tracks where cd_id='$cd_id'") or die(mysql_error());  
    //$a = @mysql_fetch_array($r);
    
$cd_title = $_GET["cd_title"];
    $t = @mysql_query("select * from cds where cd_title='$cd_title'") or die(mysql_error());  
    $i = @mysql_fetch_array($t);
?>
<title>Add Tracks for [<?php echo "{$cd3['cd_band']} - {$cd3['cd_title']}"; ?>]</title>
<p>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<input name="cd_id" type="text" value="<?php echo $_GET['cd_id']; ?>" readonly="true">
<input name="cd_title" type="hidden" value="<?php echo "{$cd3['cd_title']}"; ?>" readonly="true">

<table width="100%" border="1" class="InternalHeader">
  <tr>
    <td width="10%" align="center">CD Track No.&nbsp;</td>
    <td width="100%" align="center">CD Track Title&nbsp;</td>
  </tr>
</table>
<table width="100%" border="0" class="NormalTableTwo">
  <tr>
    <td width="10%" align="center"><input name="cd_trackno" type="text" size="5"></td>
    <td width="100%" align="center"><input name="cd_tracktitle" type="text" size="100"></td>
  </tr>

</table>

Adding tracks for <?php echo "{$cd3['cd_band']}"; ?> - <?php echo "{$cd3['cd_title']}"; ?>
<br>
<input name="save" type="submit" value="Save Tracks">
</form>
</p>
<?php
  else:
        // Connect to the database server
    include("connect.php");
        $cd_id = $_POST['cd_id'];
        $cd_title = $_POST['cd_title'];
    $cd_trackno = $_POST['cd_trackno'];
    $cd_tracktitle = $_POST['cd_tracktitle'];
     // If CD has been submitted,
    // add it to the database.
    if ($save == "Save Tracks") {

      $sql = "INSERT INTO $table1 SET
                cd_id='$cd_id',
              cd_title='$cd_title',
              cd_trackno='$cd_trackno',
              cd_tracktitle='$cd_tracktitle'";
      
      if (@mysql_query($sql)) {
        echo("<P>CD Track(s) (<b>$cd_trackno - $cd_tracktitle</b>) saved.</P><a href=tracks.php?cd_id=$cd_id&tracks&cd_title=$cd_title>DONE</a> | <a href=tracks.php?cd_id=$cd_id&addtracks>Add another Track</a>");
      } else {
        echo("<P>Error saving Track <b>$cd_trackno - $cd_tracktitle</b>:<br> "
.
             mysql_error() . "</P>");
      }
    }

endif;

?>
[/code]

Any help would be greatly appriciated.
Link to comment
https://forums.phpfreaks.com/topic/12215-querying-from-a-link/
Share on other sites

why so many {} you don't need them. They're only for $var{$string}


<a href='tracks.php?cd_id={$cd3['cd_id']}&tracks&cd_title={$cd3['cd_title']}'>Tracks</a>

Is this in html or in an echo?
if it's in html

?><a href="tracks.php?cd_id=<?=$cd3['cd_id']?>&tracks&cd_title=<?=$cd3['cd_title']?>">Tracks</a><?

In any case this line:

$cdl = @mysql_query("select * from cds where cd_id={$_GET['cd_id']}");

will not work if $_GET['cd_id'] is not set so you should have an if() statement around it to provent issues
Link to comment
https://forums.phpfreaks.com/topic/12215-querying-from-a-link/#findComment-46600
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.