Results 1 to 2 of 2

Thread: PHP, mySQL

  1. #1
    Join Date
    Mar 2007
    Posts
    8

    Question PHP, mySQL

    I'm creating a web site for free sound effects and i have a database that has (or atleast will) have the details of each sound effect in it.

    The table has the following fields:
    name
    description
    path
    price (not important)
    catergories

    I have pages for each category and i need the page to read the database and get the names of all the sounds in that catergoy. I also would like it to then read the path each individual file and put the filename at the end.

    so say the file name was sound1.mp3

    and the path was http://www.soundhost.com/sounds/

    i'd need it to link the word sound1.mp3 on the page to link to the file.
    http://www.soudhost.com/sounds.

    Can anyone help me with this.

    thanks in advance
    Sean G

  2. #2
    Join Date
    Jun 2007
    Location
    Boston
    Posts
    7

    Post

    I will use a multi-file system for best results and more efficient practice.

    file number 1: dbconfig.php
    Code:
    <?php
      $dbhost = 'localhost'; // set this to your database server address.
      $dbuser = 'username';
      $dbpass = 'password';
      $dbname= 'databaseName';
    
      $con = mysql_connect($dbhost, $dbuser, $dbpass) or die('MySQL error: '. mysql_error();
      mysql_select_db($dbname, $con);
    ?>
    file number 2: closedb.php
    Code:
    <?php
      mysql_close($con);
    ?>
    This second file is important to include at the footer of a page in which you open a connection, it will make your server very happy!.
    On to the heart of the matter.

    To get the data we need...
    Code:
    <html>
    <head></head>
    <body>
    <div id="container">
    
    <?php
      include './dbconfig.php';
    
      $query = "SELECT `name`, `description`, `path`, `price` FROM `tablename` WHERE `catergory`='categoryName'";
      $result = mysql_query($query);
    
      while($row = mysql_fetch_array($result, mysql_assoc))
      {
        // Here we will place the data on the site in whatever format.
       ?>
       <a href"/<?print $row['path'] . '/' .$row['filename'] . '.ext'; ?>"><? print $row['name']; ?></a>
       <?
         // or you can do it in the code
         echo ' <a href="/' .$row['path'] . '/' .$row['filename'] . '.ext">'. $row['name'] . '</a>';
       }
       // be nice to your server
       mysql_free_result($result);
    ?>
    </div>
    
    <? include './dbclose.php'; ?>
    </body>
    </html>
    Cheers
    /K

    ---------------------------
    W3-Edge.com

Similar Threads

  1. Retrieving data from MySQL basic PHP
    By WongFei in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 10 Feb 2007, 02:17 PM

Posting Permissions

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