PDA

View Full Version : PHP, mySQL



rabbitkillrun
02 Jun 2007, 08:27 AM
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

k-edge
05 Jun 2007, 01:42 PM
I will use a multi-file system for best results and more efficient practice.

file number 1: dbconfig.php


<?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


<?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...


<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 (http://www.w3-edge.com/)