This PHP script exists soley so that I don't have to change dozens of pages whenever I change the location of a page, or remove it from my website. It reads the internal links in from a MySQL database (soon to be converted to use the PEAR framework), and lists the links by category wherever you call the function from.
I know this code is somewhat sloppy, but it's a first attempt at PHP so... comment away.
Also I have a css entry for my menu items set up, hence the class="menu". Take a look at http://www.DanielGrantTaylor.com for a short view of this code in action. It creates the menu at the bottom of every page.
By : mulciber316
<?php function printconstantlinks() { // Variables: $lastcategory = FALSE; // The last link category seen. Cheat a bit here to say if we've seen a link category yet. $serverlocation = "localhost"; $username = "mywebsiteusername"; $password = "mywebsiteuserpassword"; $db_name = "mywebsitedatabase"; // Now we want to display all the links we want on every page,
// Get a connection to the database first. $conn = mysql_connect($serverlocation, $username, $password) or die("Could Not Connect To Server"); mysql_select_db($db_name) or die("Could not use database for website");
// Now, we want to order our links by their category, and then their caption. $query = "SELECT link_type, link_caption, link_location FROM internal_links ORDER BY link_type, link_caption"; $result = mysql_query($query) or die("Query failed.");
print "<p class=\"menu\">"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { extract($line); if ($lastcategory != $link_type) { if ($lastcategory) print "<br />\n";
mysql_free_result($result); mysql_close($conn); } ?> /////////////////////////////////////////////// #MySQL syntax to create internal_links table: CREATE TABLE internal_links ( _handle INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, link_caption TEXT, link_location TEXT NOT NULL, link_type ENUM("Business", "Personal", "Projects", "Scholastic", "Navigation") );
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.