Forum Moderators: coopster
My issue is as follows:
I've got a database with a table called categories(ID, Name, Active, Url, Alt).
then i've got tables for each category [pagenamewithoutexteion] + 'page' i.e indexpage ( ID,Name, Active, URL, Alt, Category)
what happens is this.
<div 1>
loadpages();
</div 1>
<div 2>
loadpages();
</div>
the first loads the pages in the category table
Home - Faq - etc - etc
the second then loads the pages that are in a sense linked to the category you are viewing.
News - updates - todo
that all works fine
function loadPages( $class, $subpage)
{
$fname = $_SERVER['PHP_SELF'];
$fname = Explode('/', $fname);
$fname = end($fname);
if($subpage == 1)
{
$query = 'SELECT id, name, url, active, alt, cate FROM ' . $_SESSION['category'] . ' ORDER BY id';
}
else
{
$query = 'SELECT id, name, url, active, alt, cate FROM categories ORDER BY id';
}
$msresult = mysql_query($query) or die('Error, query failed. ' . mysql_error());
if ( mysql_num_rows($msresult) == 0 && $subpage != 1)
{
echo("There appears to be no pages for this site.");
}
else if (mysql_num_rows($msresult) == 0)
{
echo('There are no addtional pages to this section');
return 0;
}
while($row = mysql_fetch_array($msresult))
{
list($id, $name, $url, $active, $alt) = $row;
if ( $active == 1)
{
if ( $url != $fname)
{
echo('<div class=' . $class .'><a href=" ' .$url . '"> ' . $name . ' </a></div>');
continue;
}
else if ($url == $fname)
{
echo('<div class=' . $class .'><a href=" ' . $url . '"><strong>' . $name . ' </strong> </a></div>');
continue;
}
}
else
{
continue;
}
}
}
the code above loads the pages.
what i am trying to do is when your on page news.php because its a subcategory of index.php i want to bold then both, but i can't work out how to do it. the function is called twice in two different place due to style layout of the page.
my issue is.
because the main categories are loaded first, then the subpages. i can't fiqure out how to bold the index because its already been loaded.
If you can give me any advice that would be amazing!
[edited by: AWSwS at 12:27 pm (utc) on July 25, 2008]
Table - Categories (ID, Name, Url, Alt, Active,Pageids(array))
Table - Pages(ID, Name, Url, Alt, Active, Cid, Pvars)
what i did was to redesign the database and the code, now the pages have CID which is the category id, which is the same id as the main category and pvars which is the varibles on that id, currently i has the category on it.
i load in the categories, then the subpages. if viewing a sub page load all in as normal, but highligh the category your in and the page your in.
function loadPages()
{
$fname = $_SERVER['PHP_SELF']; // Get file name
$c = $_GET['c'];
$fname = Explode('/', $fname); // Seperate the parts [root], [folder depth] , [file name]
$fname = end($fname); // moves to the end of the array [filename]
$pages = 0;$query = 'SELECT id, name, url, alt, active, pageids FROM categories ORDER BY id';
$msresult = mysql_query($query) or die('Error, query failed. ' . mysql_error());
if (mysql_num_rows($msresult) == 0)
{
echo('There Appears to be no pages in this site');
return 0;
}
echo('<div class="menu">');
while($row = mysql_fetch_array($msresult))
{
list( $id, $name, $url, $alt, $active, $pagids) = $row;
if ( $url == $fname ¦¦ $c == $id)
{
echo('<div class="menu_entries"><a href=" ' . $url . '"><strong>' . $name . ' </strong> </a></div>');
$pages = $id;
continue;
}
else if ( $url != $fname)
{
echo('<div class="menu_entries"><a href=" ' .$url . '"> ' . $name . ' </a></div>');
continue;
}
}
echo('</div>');
echo('</div>');
echo('</div>');
echo('<div class="submenu"> ');
if( $pages != 0)
{
$query = 'SELECT id, name, url, alt, active, cid, pvars FROM pages WHERE cid= '. $pages;
}
else if($c == 0)
{
echo("There appears to be no additional pages to this category");
echo('</div>');
return;
}
else
{
$query = 'SELECT id, name, url, alt, active, cid, pvars FROM pages WHERE cid= '. $c;
}
$msresult = mysql_query($query) or die('Error, query failed. ' . mysql_error());
while($row = mysql_fetch_array($msresult))
{
list( $id, $name, $url, $alt, $active, $cid, $pvars) = $row;
if ( $url != $fname)
{
$url = $url . $pvars;
echo('<div class="submenu_entries"><a href=" ' .$url . '"> ' . $name . ' </a></div>');
continue;
}
if ( $url == $fname)
{
echo('<div class="submenu_entries"><a href=" ' . $url . $pvars . '"><strong>' . $name . ' </strong> </a></div>');
continue;
}
}
echo('</div>');
}
it works, it doesn't display a message when there are no additional pages i've got that to work out, but asides that it works how i wanted it too.
[edited by: AWSwS at 3:54 pm (utc) on July 25, 2008]
Table - Categories (ID, Name, Url, Alt, Active,Pageids(array))
Table - Pages(ID, Name, Url, Alt, Active, Cid, Pvars)
what i did was to redesign the database and the code, now the pages have CID which is the category id, which is the same id as the main category that the subpage resides in.
i load in the categories, then the subpages. If your viewing a main category but not a subpage then the category name is in bold, if your viewing a subpage of a category then the subpage and the category is bolded.
i've also removed the need for the pvars varible.
function loadPages()
{
$fname = $_SERVER['PHP_SELF']; // Get file name
$fname = Explode('/', $fname); // Seperate the parts [root], [folder depth] , [file name]
$fname = end($fname); // moves to the end of the array [filename]
$pages = 0;$query = 'SELECT cid FROM pages where url= "' . $fname .'"';
$c = mysql_query($query) or die ('Error, query failed. ' . mysql_error());
if (mysql_num_rows($c) != 0)
{
$item = mysql_fetch_array($c);
$c = $item['cid'];
}
$query = 'SELECT id, name, url, alt, active, pageids FROM categories ORDER BY id';
$msresult = mysql_query($query) or die('Error, query failed. ' . mysql_error());
if (mysql_num_rows($msresult) == 0)
{
echo('There Appears to be no pages in this site');
return 0;
}
echo('<div class="menu">');
while($row = mysql_fetch_array($msresult))
{
list( $id, $name, $url, $alt, $active, $pagids) = $row;
if ( $url == $fname ¦¦ $c == $id)
{
echo('<div class="menu_entries"><a href=" ' . $url . '"><strong>' . $name . ' </strong> </a></div>');
$pages = $id;
continue;
}
else if ( $url != $fname)
{
echo('<div class="menu_entries"><a href=" ' .$url . '"> ' . $name . ' </a></div>');
continue;
}
}
echo('</div>');
echo('</div>');
echo('</div>');
echo('<div class="submenu"> ');
if( $pages != 0)
{
$query = 'SELECT id, name, url, alt, active, cid, pvars FROM pages WHERE cid= '. $pages;
}
else if($c == 0)
{
echo("There appears to be no additional pages to this category");
echo('</div>');
return;
}
else
{
$query = 'SELECT id, name, url, alt, active, cid, pvars FROM pages WHERE cid= '. $c;
}
$msresult = mysql_query($query) or die('Error, query failed. ' . mysql_error());
while($row = mysql_fetch_array($msresult))
{
list( $id, $name, $url, $alt, $active, $cid, $pvars) = $row;
if ( $url != $fname)
{
$url = $url . $pvars;
echo('<div class="submenu_entries"><a href=" ' .$url . '"> ' . $name . ' </a></div>');
continue;
}
if ( $url == $fname)
{
echo('<div class="submenu_entries"><a href=" ' . $url . $pvars . '"><strong>' . $name . ' </strong> </a></div>');
continue;
}
}
echo('</div>');
}