PHP PROJECT

README.md

Add, List, Edit and Delete

Add, List, Edit and Delete records in MySQL tables. It can connect to a MySQL database using MySQLi and generate listing of records of a database table with support to paginate the listings with a limited amount of records.

Files


NameTypeSizeLast Modified
aed-pager-class.php phpfile icon 2328 11 November 2015 10:49:52
aed-example.php phpfile icon 3163 11 November 2015 10:49:52
aed-config.php phpfile icon 462 11 November 2015 10:49:52
aed.sql sqlfile icon 263 11 November 2015 10:49:52
aed-class.php phpfile icon 2924 11 November 2015 10:49:52
aed-template.htm textfile icon 1685 11 November 2015 10:49:52

Source

  1. <?php
  2. /**
  3.  * PHP ADD EDIT DELETE EXAMPLE
  4.  * @author admin@v23.in - http://v23.in
  5.  * @version 1.0.0
  6.  * @date October 21, 2015
  7. */
  8. require "aed-class.php";
  9. require "aed-pager-class.php";
  10. require "aed-config.php";
  11. // chage only aed-config.php file --------------------------------------------
  12. //-------------- no need to change -------------------------------------------
  13. $db = new aed(DB_HOSTDB_USERDB_PASSDB_NAME);
  14. // page = PAGE NUmBER  Default value page = 1;
  15. if(isset($_GET['page']))
  16. $page =    $_GET['page'];
  17. else
  18. $page 1;
  19. if(empty($page) || $page 1)
  20. $page 1;
  21. // LIMIT 1, perPage Display
  22. $start=($page 1) * $perPageDiaplay;
  23. $totalRow $db->totalPage($table);
  24. // Filename, Page =p , total Row, Current Page Value - Default 1, Per Page Display - Default 12
  25. //$output['pager']=pager("$filename?","page=",$totalRow,$page,$perPageDiaplay);
  26. $output['pager'] = "";
  27. if($totalRow 0){
  28. $pager = new pager($filename,$totalRow,$page,$perPageDiaplay);
  29. $output['pager'] = $pager->DisplayCenter();
  30. }
  31. $ar $db->makeTTArray($table);
  32. $error="Welcome!";
  33. if(isset($_POST['Action']) && isset($_GET['ip']) && ($_POST['Action'] == $_GET['ip'])){
  34.     foreach($ar as $k=>$v){
  35.     if(isset($_POST[$k]))
  36.     $arr[$k]=$_POST[$k];
  37.     
  38.     }
  39.         if(isset($_POST['route']) && ($_POST['route'] == "add" || $_POST['route'] == "Create") ){
  40.         $error=$db->check($table,$arr);
  41.         if(!$error)
  42.         $error $db->insert($table,$arr);
  43.         }
  44.         elseif(isset($_POST['route']) && $_POST['route'] == "edit"){
  45.         $error $db->update($table,$arr,"`$primeryKEY`=".$_POST['CusID']." LIMIT 1");
  46.         }
  47.         elseif(isset($_POST['route']) && $_POST['route'] == "del"){
  48.         $error $db->delete($table,"`$primeryKEY`=".$_POST['CusID']." LIMIT 1");
  49.         }
  50. }
  51. $output['error']='<p class="bg-info">'.$error.'</p>';
  52. if(isset($_GET['c']) && isset($_GET['id'])){
  53. $cc=$_GET['c'];
  54. $id=$_GET['id'];
  55. $ar $db->query2row("SELECT * from $table where $primeryKEY = $id LIMIT 1");
  56. }
  57. else{
  58. $cc="Create";
  59. $id=0;
  60. }
  61. if($fieldRequire == 'ALL'){
  62. $output['foo']=$ar;
  63. unset($output['foo'][$primeryKEY]);
  64. }
  65. else
  66. {
  67. $o=explode(",",$fieldRequire);
  68. $output['foo']=array_flip($ar);
  69. }
  70. $output['page']=$page;
  71. $output['timeid'] = microtime(true);
  72. $output['filename']=$filename;
  73. $output['cc']=$cc;
  74. $output['id']=$id;
  75. $output['row']=$ar;
  76. $field implode(", "array_keys($output['foo']));
  77. $sql="SELECT $primeryKEY$field from $table ORDER BY $primeryKEY DESC LIMIT ".$start.",".$perPageDiaplay;
  78. $row=$db->query($sql);
  79. if($row->num_rows 0){
  80. while($result $row->fetch_assoc()){
  81. $result['command']="<a href='$filename?id=".$result[$primeryKEY]."&c=add&page=$page'><span class=\"glyphicon glyphicon-check\" aria-hidden=\"true\"></span></a> <a href='$filename?id=".$result[$primeryKEY]."&c=edit&page=$page'><span class=\"glyphicon glyphicon-edit\" aria-hidden=\"true\"></span></a> <a href='$filename?id=".$result[$primeryKEY]."&c=del&page=$page'><span class=\"glyphicon glyphicon-trash\" aria-hidden=\"true\"></span></a> ";
  82. $output['row'][]=$result;
  83. }
  84. }
  85. else
  86. $output['row']=array();
  87. echo render_temp("aed-template.htm",$output);
  88. $db->close();
  89. ?>

Demo

You can find a demo available here: aed

Requirment

  • mySql
  • PHP >= 5.4
  • Apache Server

Contribute

  • Vishv Sahdev

Example

>>

Download