Hi all
I am pretty new to website design and am trying to incorporate my website into a database. At the moment I am simply trying to put some basic code together and will finalise details later.
I have however come accross a problem, I have managed to get working code to display the content of the website, extracting it from a field in the database. I then made working code to get the menu do display also from the database. However, when these are both combined, the menu displays, but the content does not display.
I think this may have to do with reusing the variable $row, but I don't know if this is certain, and I don't know how to correct this. The basic code is below: (hope this displays right, I am new to BB tags too)
Below is the menu.php file, called from the header file, called from the main page handler. Basically, every page directs to the main page, with a variable in the header, this is read and the appropriate content extracted from the database, meaning that one page can handle all pages and meaning everything else can be in the database. It might not be the best way, but its the best way I could come up with.
}
mysql_free_result($link_result);
}
else
# If no result, Display an error message
{
echo 'Error - Menu Not Found - Please Try Agin later - Sorry For Any Inconvienience';
}
#now trying for additional menu items
$link_query = 'SELECT catagory, link_text, link_title, link_href FROM links WHERE catagory=\'MORE STUFF\' ORDER BY link_id ASC';
$link_result = @mysql_query($link_query);
if ($link_result)
# If result found, process the page
{
echo ('<h3>More Stuff</h3>');
while ($row = mysql_fetch_array($link_result, MYSQL_NUM))
{
echo ('<li><a href="' . $row[3] . '"');
if (isset($row[2]))
{
echo (' title="' . $row[2] . '"');
}
echo ('>');
if (isset($row[1]))
{
echo $row[1];
}
echo ('</a></li>');
}
mysql_free_result($link_result);
}
?>
Below is the main page handling script.
<?php
# Accessing the selected page url tag
$page_url = $_GET['page'];
if (empty($page_url))
{
#No value entered, therefore default home page
$page_url = '\'home\'';
}
# Connect to database
require_once ('mysql_guest_connect.php');
$query = 'SELECT page_title, page_cont FROM pages WHERE page_url=' . $page_url;
$result = @mysql_query($query);
if ($result)
# If result found, process the page
{
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
$page_title = $row[0];
include ('header.inc');
echo $row[1];
}
include ('footer.inc');
}
else
# If no result, Display an error message
{
echo 'Error - Page not found';
}
?>
Thank you for any help in advance. I hope i have given enough information to allow you wonderful people to help!
Thanks again
Andy Turner