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