Okay the categories would need to have their own table.
If you have any sub categories then you would need to create an ability to check which category it has for a parent.
an example db setup for your table could be
categories table
Code:
cat_id
parent_id
cat_title
cat_desc
then you create a php function that will loop through the table and grab everything from the from the categories table and parses it onto the page template
PHP Code:
$db = array(
'host' => 'http://www.domain.com',
'user' => 'username',
'pass' => 'password',
'db' => 'database'
);
function getCategories($parent)
{
$conn = @mysqli_connect($db['host'], $db['user'], $db['pass'], $db['db']);
// Checks if a connection can be made, attempts to run a query and return results
if($conn)
$sql = "SELECT cat_id, cat_title, cat_desc FROM categories WHERE parent_id = '". $parent ."'";
if($rs = mysqli_query($sql))
{
while($result = mysql_fetch_array($rs))
{
$cat[] = array(
'ID' => $result['cat_id'],
'TITLE' => $result['cat_title'],
'DESC' => $result['cat_desc'],
)
}
}
else
{
echo "Unable to Execute Query";
}
}
else
{
echo "Unable to Connect to Database";
}
// Checks if categories exist and attempts to print them to the page
if(is_array($cat))
{
echo '<ul id="menu">';
foreach($cat as $c)
{
echo '<li><a href="'. $c['CAT_ID'] .'" title="'. $c['DESC'] .'">'. $c['TITLE'] .'</a></li>';
}
echo '</ul>';
}
}
Bookmarks