PHP - Agregar opciones de View/Edit/Del.

 
Vista:

Agregar opciones de View/Edit/Del.

Publicado por Carlos (1 intervención) el 14/07/2014 18:13:10
Hola,

Quisiera poder agregarle a los módulos de mi sistema web las opciones View/Edit/Del. Por ejemplo, al módulo de Clientes. No soy el creador del sistema así que se me complica mucho, aparte no tengo mucho conocimiento de programación.
Quiero poder agregar, editar y eliminar cualquier cliente que se encuentre en la base de datos.

client.html


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<div ng-include="'views/menu.html'">
</div>
<button type="button" class="btn btn-primary" ng-model = 'newProduct' ng-click = 'newProductButton()'>{{buttonName}}</button>
<hr>
<div class="table-responsive" ng-show ='!newProduct'>
<table class="table table-striped table-hover">
<tr>
<td></td>
<td>Cédula</td>
<td>Nombre</td>
<td>Apellido</td>
<td>Dirección</td>
<td>Email</td>
<td>Télefono</td>
</tr>
<tr ng-repeat= 'client in clients track by $index'>
<td>{{$index + 1}}</td>
<td>{{client.codigo}}</td>
<td>{{client.nombre}}</td>
<td>{{client.apellido}}</td>
<td>{{client.direccion}}</td>
<td>{{client.email}}</td>
<td>{{client.telefono}}</td>
</tr>
</table>
</div>
<div ng-show = 'newProduct'>
<form role="form" ng-submit ="updateClient (id,name,lastName,address,phoneNumber,email)">
<label>Cédula</label>
<div class="form-group">
     <input class="form-control" placeholder="Cédula" ng-model='id' id="id">
   </div>
   <label>Nombre</label>
   <div class="form-group">
     <input class="form-control" placeholder="Nombre" ng-model='name' id="sname">
   </div>
   <label>Apellido</label>
   <div class="form-group">
     <input class="form-control" placeholder="Apellido" ng-model='lastName' id="lastName">
   </div>
   <label>Dirección</label>
   <div class="form-group">
     <input class="form-control" placeholder="Dirección" ng-model='address' id="address">
   </div>
   <label>Teléfono</label>
   <div class="form-group">
     <input type='tel' class="form-control" placeholder="Teléfono" ng-model='phoneNumber' id="phoneNumber">
   </div>
   <label>Email</label>
   <div class="form-group">
     <input type='email'class="form-control" placeholder="Email" ng-model='email' id="email">
   </div>
      <div class="alert alert-success" id='alertSuccess' style="display:none">Ingresado Satisfactoriamente...</div>
      <div class="alert alert-danger" id='alertDanger' style="display:none">Ese cliente ya fue agregado</div>
   <button type="submit" class="btn btn-primary">Agregar Cliente</button>
  </form>
</div>


client.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
 
 
/**
 * @ngdoc function
 * @name belkitaerpApp.controller:ClientCtrl
 * @description
 * # ClientCtrl
 * Controller of the belkitaerpApp
 */
angular.module('belkitaerpApp')
  .controller('ClientCtrl', function ($scope,$http) {
    $scope.newProduct = false;
   if($scope.newProduct){
   $scope.buttonName = 'Ver Tabla';
   }
   else{
   $scope.buttonName = 'Ingresar Cliente';
   }
   $http.get('../serverSide/clients.php').success(function(clients){
   console.log(clients);
   $scope.clients = clients.Clients;
   })
   $scope.newProductButton  = function(){
   $scope.newProduct = !$scope.newProduct;
   if($scope.newProduct){
   $scope.buttonName = 'Ver Tabla';
   }
   else{
   $scope.buttonName = 'Ingresar Cliente';
   }
   }
    $scope.updateClient = function(id,name,lastName,address,phoneNumber,email){
      $http.post('../serverSide/updateClient.php',{id:id,name:name,lastName:lastName,address:address,phoneNumber:phoneNumber,email:email}).success(function(data){
        console.log(data);
        $('#alertSuccess').show("slow");
          setTimeout(function() {
            $('#alertSuccess').hide('slow');
          }, 3000);
      }).error(function(data){
        console.log(data);
        $('<div id="alertDanger"></div>').show("slow");
          setTimeout(function() {
            $('<div id="alertDanger"></div>').hide('slow');
          }, 3000);
      })
    }
  });


client.php


1
2
3
4
5
6
<?php
require_once 'database.php';
$db = new Database();
$clients = $db->queryAll('SELECT clie_id as id,clie_cod as codigo, clie_ape as apellido, clie_nom as nombre, clie_dir as direccion, clie_ema as email, clie_tel as telefono FROM cliente','Clients');
echo json_encode($clients);
?>


Conseguí un código que se encarga de ejercer la función que necesito y me gustaría saber si se podría combinar con el que ya poseo. Lo probé con mi base de datos y funciona perfectamente.

Acá el código:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
if (isset($_POST['submit']))
{
include 'db.php';
 
 
$clie_cod=$_POST['clie_cod'] ;
$clie_ape= $_POST['clie_ape'] ;
$clie_nom=$_POST['clie_nom'] ;
$clie_dir=$_POST['clie_dir'] ;
 
 
mysql_query("INSERT INTO `cliente`(Código,Apellido,Nombre,Dirección)
VALUES ('$clie_cod','$clie_ape','$clie_nom','$clie_dir')");
 
 
 
 
       }
?>
</form>
<table border="1">
 
 
<?php
include("db.php");
 
 
 
 
$result=mysql_query("SELECT * FROM cliente");
 
 
while($test = mysql_fetch_array($result))
{
$id = $test['clie_id'];
echo "<tr align='center'>";
echo"<td><font color='black'>" .$test['clie_id']."</font></td>";
echo"<td><font color='black'>" .$test['clie_cod']."</font></td>";
echo"<td><font color='black'>". $test['clie_ape']. "</font></td>";
echo"<td><font color='black'>". $test['clie_nom']. "</font></td>";
echo"<td><font color='black'>". $test['clie_dir']. "</font></td>";
echo"<td> <a href ='view.php?clie_id=$id'>Edit</a>";
echo"<td> <a href ='del.php?clie_id=$id'><center>Delete</center></a>";
 
 
echo "</tr>";
}
mysql_close($conn);
?>
</table>
 
 
</body>
</html>



Cualquier ayuda será bien apreciada. Muchísimas gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder