query($sql); $navSections = array(); while ($row = mysql_fetch_array($result)) { $navSections[$row['id']]['id'] = $row['id']; $navSections[$row['id']]['name'] = $row['name']; } //////////////////////////////////////////////////////////////////////////////// // work out if we are in a category - if we are, display the sub-category links // and pages in the immediate category if ( isset($_GET['section'])) { // we are displaying a specific section // get all sub-sections of this section $sql = sprintf("SELECT * FROM sections WHERE parent = '%s'", makeSafe($_GET['section']) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $insideSections[$row['id']]['id'] = $row['id']; $insideSections[$row['id']]['name'] = $row['name']; } } // get all pages in this section $sql = sprintf("SELECT * FROM pages WHERE section = '%s'", makeSafe($_GET['section']) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $sectionPages[$row['id']]['id'] = $row['id']; $sectionPages[$row['id']]['title'] = $row['title']; } } // get the default page for this section $sql = sprintf("SELECT default_page FROM sections WHERE id = '%s'", makeSafe($_GET['section']) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { if (mysql_result($result, 0, "default_page") != "") { // a page exists! $sql = "SELECT * FROM pages WHERE id = '" . mysql_result($result, 0, "default_page") . "'"; $result = $mysql->query($sql); if (mysql_num_rows($result)) { $pageTitle = mysql_result($result, 0, "title"); $pageContent = mysql_result($result, 0, "content"); } } else { // no default page exists, so try to get ANY page $sql = sprintf("SELECT * FROM pages WHERE section = '%s'", makeSafe($_GET['section']) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { // pages exist in this section, so choose the first page $pageTitle = mysql_result($result, 0, "title"); $pageContent = mysql_result($result, 0, "content"); } else { // no pages exist in this section! $pageContent = "Sorry, no default page exists for this section."; $pageTitle = "Page Not Found!"; } } } } else if ( isset($_GET['page']) ) { // we are displaying a specific page // work out the section this page is in $sql = sprintf("SELECT * FROM pages WHERE id = '%s'", makeSafe($_GET['page'])); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { $pageSection = mysql_result($result, 0, "section"); $pageTitle = mysql_result($result, 0, "title"); $pageContent = mysql_result($result, 0, "content"); // get all sub-sections of this section $sql = sprintf("SELECT * FROM sections WHERE parent = '%s'", makeSafe($pageSection) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $insideSections[$row['id']]['id'] = $row['id']; $insideSections[$row['id']]['name'] = $row['name']; } } // get all pages in this section $sql = sprintf("SELECT * FROM pages WHERE section = '%s'", makeSafe($pageSection) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $sectionPages[$row['id']]['id'] = $row['id']; $sectionPages[$row['id']]['title'] = $row['title']; } } } else { // page doesn't exit } } else { // we are not in a page or section - display the homepage $sql = "SELECT * FROM pages WHERE id = '9'"; $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { $pageTitle = mysql_result($result, 0, "title"); $pageContent = mysql_result($result, 0, "content"); } else { $pageTitle = "Unknown Page"; $content = "Sorry, you have specified a non-existant page!"; } } //////////////////////////////////////////////////////////////////////////////// // Assign contents to variables for the template $smarty->assign('title', $pageTitle); // This is the page title, as displayed in the title bar $smarty->assign('content', $pageContent); // This is the page content! $smarty->assign('navSections', $navSections); // This is the links for the navigation bar $smarty->assign('insideSections', $insideSections); // This is for the sub-sections of this section $smarty->assign('sectionPages', $sectionPages); // This is for all the pages which belong to this category //////////////////////////////////////////////////////////////////////////////// $smarty->display('photos.tpl'); ?>