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.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help needed making link from db output

    Hi all,

    I have a page named choice.php, which displays a dropdown filled with categories, (A-Z), which lets the user choose a category.
    In the categories are artists which get displayed depending on which category they reside, and which category the user chooses.
    These get displayed using view.php. EG...(http://www.dsfghrt.com/view.php?id=1). Category A is number 1 in database, B=2, c=3, and so on.

    What i wish to know is how can i make each artist name into a link, which will then display the rest of the info on another page.
    This info is also in the database under artist_name, album_name and album_info.

    Thanks all,

    Steve


    BTW...Here is the code for choice.php and view.php

    Choice.php

    Code:
    <?php require('Connections/xxx.php'); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    <form action="view.php" method="GET">
      <div align="center">
        <select name="category">
          <option>Browse Category</option>
          <option value="1">A</option>
          <option value="2">B</option>
          <option value="3">C</option>
          <option value="4">D</option>
          <option value="5">E</option>
          <option value="6">F</option>
          <option value="7">G</option>
          <option value="8">H</option>
          <option value="9">I</option>
          <option value="10">J</option>
          <option value="11">K</option>
          <option value="12">L</option>
          <option value="13">M</option>
          <option value="14">N</option>
          <option value="15">O</option>
          <option value="16">P</option>
          <option value="17">Q</option>
          <option value="18">R</option>
          <option value="19">S</option>
          <option value="20">T</option>
          <option value="21">U</option>
          <option value="22">V</option>
          <option value="23">W</option>
          <option value="24">X</option>
          <option value="25">Y</option>
          <option value="26">Z</option>
        </select> 
        <input type="submit">
      </div>
    </form>
    </body>
    </html>
    View.php

    Code:
    <?php require('Connections/xxx.php'); ?>
    <?php
    $maxRows_Recordset1 = 10;
    $pageNum_Recordset1 = 0;
    if (isset($_GET['pageNum_Recordset1'])) {
      $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
    }
    $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
    
    $colname_Recordset1 = "-1";
    if (isset($_GET['category'])) {
      $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['category'] : addslashes($_GET['category']);
    }
    mysql_select_db($database_xxxdb, $xxxdb);
    $query_Recordset1 = sprintf("SELECT id, artist_name, album_title, category FROM upload2 WHERE category = '%s' ORDER BY artist_name DESC", $colname_Recordset1);
    $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
    $Recordset1 = mysql_query($query_limit_Recordset1, $xxxdb) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    
    if (isset($_GET['totalRows_Recordset1'])) {
      $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
    } else {
      $all_Recordset1 = mysql_query($query_Recordset1);
      $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
    }
    $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
    ?>
    <link href="/standard.css" rel="stylesheet" type="text/css">
    
    <style type="text/css">
    <!--
    .style10 {
    	font-size: 14;
    	color: #999933;
    }
    -->
    </style>
    <title>xxx - Search Results</title><p>&nbsp;</p>
    <div align="center" class="style1 style10">
      <p><?php echo $totalRows_Recordset1 ?> Category Result Found<br>
      </p>
    </div>
    <table width="383" border="0" align="center" cellpadding="8" cellspacing="5">
      <tr>
        <td><div align="center" class="style5">Artist / Group </div></td>
        <td><div align="center" class="style5">Album Title </div></td>
      </tr>
      
      <?php do { ?>
        <tr>
          <td class="style6"><div align="center"><?php echo $row_Recordset1['artist_name']; ?>
    </div></td>
          <td class="style6"><div align="center"><?php echo $row_Recordset1['album_title']; ?></div></td>
        </tr>
    
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>
    <?php
    mysql_free_result($Recordset1);
    ?>
    Last edited by Stevis2002; 05-07-2006 at 12:56 PM.

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's easy to create a link with the artist ID


    Create a new page for artist detail.
    For the query use the id variable from the query string


    It would be similar to the scripts you have posted and should be a problem for you to create.

    PHP Code:
    <a href="detail.php?id=<?php echo $row_Recordset1['id']; ?>"><?php echo $row_Recordset1['artist_name']; ?></a>

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply.

    I think i had my database set up wrong, as that statement you gave me kept giving me the id of the artist category and not the artist unique id which is auto-incemented when it gets first entered into the db.

    I have now ammended the db, so instead of using numbers relating to the category (A=1, B=2 etc), i just use the letters, and the categorys are now in the same table as the artists.

    I get this funny looking url now when i go to detail.php from view.php....http://www.xxxxx.co.uk/<a%20href="detail.php?id=16">test</a>
    and i get a http error.

    How would i need to modify my code exactly, as i have been trying to sort this all day and have got nowhere

    Thanks mate,

    Steve

    View.php

    Code:
    <?php require('Connections/xxxxdb.php'); ?>
    <?php
    $maxRows_Recordset1 = 10;
    $pageNum_Recordset1 = 0;
    if (isset($_GET['pageNum_Recordset1'])) {
      $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
    }
    $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
    
    $colname_Recordset1 = "-1";
    if (isset($_GET['category'])) {
      $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['category'] : addslashes($_GET['category']);
    }
    mysql_select_db($database_xxxxdb, $xxxxdb);
    $query_Recordset1 = sprintf("SELECT id, artist_name, album_title, category FROM upload2 WHERE category = '%s' ORDER BY artist_name DESC", $colname_Recordset1);
    $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
    $Recordset1 = mysql_query($query_limit_Recordset1, $xxxxdb) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    
    if (isset($_GET['totalRows_Recordset1'])) {
      $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
    } else {
      $all_Recordset1 = mysql_query($query_Recordset1);
      $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
    }
    $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
    ?>
    <link href="/standard.css" rel="stylesheet" type="text/css">
    
    <style type="text/css">
    <!--
    .style10 {
    	font-size: 14;
    	color: #999933;
    }
    -->
    </style>
    <title>Soundflicks - Search Results</title><p>&nbsp;</p>
    <div align="center" class="style1 style10">
      <p><?php echo $totalRows_Recordset1 ?> Category Result Found<br>
      </p>
    </div>
    <table width="383" border="0" align="center" cellpadding="8" cellspacing="5">
      <tr>
        <td><div align="center" class="style5">Artist / Group </div></td>
        <td><div align="center" class="style5">Album Title </div></td>
      </tr>
      
      <?php do { ?>
        <tr>
          <td class="style6"><div align="center"><a href="&lt;a href=&quot;detail.php?id=<?php echo $row_Recordset1['id']; ?>&quot;&gt;<?php echo $row_Recordset1['artist_name']; ?>&lt;/a&gt;"><?php echo $row_Recordset1['artist_name']; ?></a>
    </div></td>
          <td class="style6"><div align="center"><?php echo $row_Recordset1['album_title']; ?></div></td>
        </tr>
    
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>
    <?php
    mysql_free_result($Recordset1);
    ?>

  • #4
    New to the CF scene
    Join Date
    May 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's ok now thanks mate...i figured it out in the end.

    Just need this in the link..../detail.php?id=<?php echo $row_Recordset1['id']; ?>

    Thanks again,

    Steve


  •  

    Posting Permissions

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