I have a question regarding how i can make my my navigation display the "correct pages".
I am trying to build a CMS, with php and Mysql.
So far I only had a table, from the DB, called "pages". I made the following code, to make this work - And made the navigation through that table:
<?php //******************PAGE DATA START SHERE*****************************************************************************
// Determine which page ID is set-----------------------------------
if (!isset($_GET['pid'])) {
$pageid = '1';
} else {
$pageid = preg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}
// Query the body section for the proper page------------------------------------------
$sqlCommand = "SELECT pagetitle, pagebody FROM pages WHERE id='$pageid' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$pagetitle = $row['pagetitle'];
$body = $row["pagebody"];
}
mysqli_free_result($query);
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------
// Query the module data for display---------------------------------------------------
$sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='footer' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$footer = $row["modulebody"];
}
mysqli_free_result($query);
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------
// BUILD MAIN NAVIGATION AND DISPLAY DATA FROM THIS-------------
$sqlCommand = "SELECT id, linklabel, pos FROM pages WHERE showing='1' ORDER BY pos ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$menuDisplay = '';
while ($row = mysqli_fetch_array($query)) {
$pid = $row["id"];
$linklabel = $row["linklabel"];
$position = $row['pos'];
$menuDisplay .= '<li><a href="index.php?pid=' . $pid . '">' . $linklabel . '' . $position . '</a></li>';
}
mysqli_free_result($query);
//******************PAGE DATA ENDS HERE*******************************************************************************
?>
This works fine!
THEN I have created another table, this is called "SUBJECTS". My intention is to make this work as a "parent", to the PAGES table. So subjects is the global navigation, and pages is showing under whatever subject it has been set to, as a local navigation.
I did the exact same when I pulled out the SUBJECTS from the database:
<?php //******************SUBJECT DATA STARTS HERE*****************************************************************************
if (!isset($_GET['sid'])) {
$subjectid = '1';
} else {
$subjectid = preg_replace("[^0-9]", "", $_GET['sid']); // filter everything but numbers for security
}
// Query the body section for the proper subject------------------------------------------
$sqlCommand = "SELECT subjecttitle, subjectbody FROM subjects WHERE id='$subjectid' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$subjecttitle = $row['subjecttitle'];
$body = $row["subjectbody"];
}
mysqli_free_result($query);
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------
// Build SUBJECT navigation and gather SUBJECT data here--------------------------------
$sqlCommand = "SELECT id, linklabel, pos FROM subjects WHERE showing='1' ORDER BY pos ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$SubjectMenuDisplay = '';
while ($row = mysqli_fetch_array($query)) {
$sid = $row["id"];
$linklabel = $row["linklabel"];
$position = $row['pos'];
$SubjectMenuDisplay .= '<li><a href="index.php?sid=' . $sid . '">' . $linklabel . '' . $position . '</a></li>';
}
mysqli_free_result($query);
//******************SUBJECT DATA ENDS HERE*******************************************************************************
?>
I have put SUBJECTS in a horizontal global menu, AND the SUBJECT links are the only ones that are working, and can display $pagebody etc etc.
The PAGES are in a left vertical menu, and not "working" when clicked on, after I integrated the subjects.
(Also I need to make the SUBJECT with id=1 be the index page).
//THIS CODE FOR PAGES
if (!isset($_GET['sid'])) {
$subjectid = '1';
} else {
$subjectid = preg_replace("[^0-9]", "", $_GET['sid']); // filter everything but numbers for security
}
//THIS CODE FOR SUBJECTS
if (!isset($_GET['sid'])) {
$subjectid = '1';
} else {
$subjectid = preg_replace("[^0-9]", "", $_GET['sid']); // filter everything but numbers for security
}
They are completely alike, and not working. It must be some if else statements, checking wheter one or the other is set or not?
Help highly appreciated :-)
If i explained badly, please let me know, and I will try to do it better.
Klemme