SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Turning text into links?

    Hi all,

    This is probably dead simple and i am overlooking something, but here goes.

    I display the category index of artists in my database via sending an id from a dropdown on a page named choice.php, to a page named view.php. (eg. All artists beggining with A, wil get called through the url, when the selection is made from the dropdown on choice.php....eg..http://www.hgvygvy.com/view.php?category=1...(A-Z, 1-26)
    What i want to know is, how can i turn the artist name for each artist, into a link to a page that displays the data for that particular artist from the database, from db fields, records artist_name,album_title, in db table upload?

    Many Thanks, Steve

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Is there an ID number for each artist? (There should be if you have structured your database sensibly). ...

    PHP Code:
    $category $_GET['category'];
    $sql "SELECT {fields} FROM table WHERE category='$category'"
    $rs mysql_query ($sql);
    while ( 
    $row mysql_fetch_array ($rs) ) {
        
    $artistid $row['artistid'];
        
    $artistname $row['artistname'];
        echo 
    '<a href="viewartist.php?artistid='.$artistid.'">'.$artistname.'</a><br />';

    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is an id for each artist, which is auto_increment.
    How would i put that query into my code?

    Here is my view.php code...

    Code:
    <?php require('Connections/xxxdb.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 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>xxxxx - 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);
    ?>
    Thanks again,
    Steve


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
  •