Posted By

jiggyhat on 05/16/09


css mysql database php tables navigation site

Versions (?)

Who likes this?

5 people have marked this snippet as a favorite


Dynamic Navigation From Database Table Names

 / Published in: PHP


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.

  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
  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>';

Report this snippet  

You need to login to post a comment.