Choose a file to view:
class_News.php
class_User.php
dbBase.php
index.php
or go back to the demo
<?php $files = scandir("."); $classList = array(); foreach($files as $file) { if(preg_match("^class_^", $file)) { include_once $file; $class = str_replace("class_","",$file); $class = str_replace(".php","",$class); $classList[] = $class; } } //include_once "class_User.php"; //include_once "class_News.php"; if(!isset($_GET['class']) || strlen($_GET['class']) == 0) {$_GET['class'] = "User";} $className = $_GET['class']; $postingObject = new $className(); if(isset($_POST['update_post'])) { $postingObject->Update($_POST); } if(isset($_POST['add_post'])) { $postingObject->Add($_POST); } $postings = $postingObject->GetAllData(); $columns = $postingObject->GetColumns(); $connection = $postingObject->GetConnectionInfo(); ?> <html> <style type="text/css"> .postTable{ width:100%; border-collapse:collapse; } .postTable td{ padding:7px; border:#4e95f4 1px solid; } /* provide some minimal visual accomodation for IE8 and below */ .postTable tr{ background: #08d1f3; } /* Define the background color for all the ODD background rows */ .postTable tr:nth-child(odd){ background: #b8d1f3; } /* Define the background color for all the EVEN background rows */ .postTable tr:nth-child(even){ background: #afffb5; } </style> <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <script> $(document).ready(function() { $('#<?php echo $className; ?>').attr('selected',true); $( "#class" ).change(function () { window.location.href='index.php?class='+$(this).val(); }); }); </script> <body> <form action="" method="get"> <label for="class">Select a data table:</label> <select id="class"> <?php foreach($classList as $class) { $selected = $class == $_GET['class'] ? "selected='selected'":""; echo "<option id='".$class."' value='".$class."' ".$selected.">".$class."</option>"; } ?> </select> </form> <table border='1' class='postTable'> <?php echo "<tr>"; foreach( $columns as $key => $val) { if($val != "posting_date") { echo "<th>".$val . "</th>".PHP_EOL; } } echo "<th> </th>".PHP_EOL; echo "</tr>".PHP_EOL.PHP_EOL; if(count($postings) > 0) { reset($postings); foreach( $postings as $posting) { echo "<tr>"; echo "<form enctype='multipart/form-data' name='update_form' id='update_form' action='index.php?class=".$className."' method='post'>".PHP_EOL; foreach( $posting as $key => $val) { if($key != "id" && $key != "posting_date") { //echo "<td><input type='text' name='".$key."' value='".$val."'></td>".PHP_EOL; echo "<td><textarea name='".$key."' id='".$key."'>".$val."</textarea></td>".PHP_EOL; } else if($key == "id") { echo "<td><textarea name='".$key."' id='".$key."' readonly>".$val."</textarea></td>".PHP_EOL; } } echo "<td><input type='submit' name='update_post' id='update_post' value='Update'></td>".PHP_EOL; echo "</form>".PHP_EOL.PHP_EOL; echo "</tr>".PHP_EOL; } } if(count($postings) > 0) {reset($postings);} echo "<tr>"; echo "<form enctype='multipart/form-data' name='add_form' id='add_form' action='index.php?class=".$className."' method='post'>".PHP_EOL; foreach( $columns as $key => $val) { if($val != "id" && $val != "posting_date") { echo "<td><input type='text' name='".$val."' value=''></td>".PHP_EOL; } else if($key == "id") { echo "<td> </td>".PHP_EOL; } } echo "<td><input type='submit' name='add_post' id='add_post' value='Add'></td>".PHP_EOL; echo "</form>".PHP_EOL.PHP_EOL; echo "</tr>".PHP_EOL; ?> </table> <p><a href="../index.php">[Back to demos home]</a> <a href="fileView.php">[View source code]</a></p> </body> </html>