Dynamic Navigation From Database Table Names


/ Published in: PHP
Save to your folder(s)

This will create a Navigation from a MySQL database table names. It removes the table name "includes" by default so you can see how to remove any certain tables you wish to not use as a site section. Just plug in your MySQL database details and connection info into data.php and you should be great to go.


Copy this code and paste it in your HTML
  1. echo '<div class="dynamic_nav_head">Navigation</div><div class="dynamic_nav">'; // on less echo
  2. include('data.php');
  3. $tables = mysql_list_tables($database);
  4. while (list($table) = mysql_fetch_row($tables)) {
  5. if($table!='includes'){
  6. $ucTable= ucwords($table); // just one function call
  7. // just one echo;
  8. // you where also using quotes and double quotes backwards
  9.  
  10. echo '<div class="cat">'.$ucTable.'</div><div class="cat_item"><a href="?page=read&section='.$table.'">View ' .$ucTable.'</a></div><div class="cat_item"><a href="?page=add&section='.$table.'">Add New '. $ucTable .'</a></div>';
  11. } // End If not in Includes.
  12. } // End While
  13. echo '</div>';

URL: http://www.onedef.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.