Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- try
- {
- //Open database connection
- $con = mysql_connect("localhost","root","itesm");
- mysql_select_db("sgv", $con);
- //Getting records (listAction)
- if($_GET["action"] == "list")
- {
- //Get record count
- $result = mysql_query("SELECT COUNT(*) AS RecordCount FROM ventas;");
- $row = mysql_fetch_array($result);
- $recordCount = $row['RecordCount'];
- //Get records from database
- $result = mysql_query("
- SELECT distinct ventas.ID_Venta, ventas.Fecha_Venta, clientes.ID_Cliente, clientes.Nombre, monedas.*
- FROM ventas,clientes, monedas
- WHERE clientes.ID_Cliente=ventas.ID_Cliente
- AND monedas.ID_Moneda=ventas.ID_Moneda ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
- //$result = mysql_query("SELECT * FROM ventas ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
- //Add all records to an array
- $rows = array();
- while($row = mysql_fetch_array($result))
- {
- $rows[] = $row;
- }
- //Return result to jTable
- $jTableResult = array();
- $jTableResult['Result'] = "OK";
- $jTableResult['TotalRecordCount'] = $recordCount;
- $jTableResult['Records'] = $rows;
- print json_encode($jTableResult);
- }
- //Creating a new record (createAction)
- else if($_GET["action"] == "create")
- {
- //Insert record into database
- $result = mysql_query("INSERT INTO clientes(Nombre, Calle, NInt, NExt, Colonia, Ciudad, Estado, Pais, CP, Telefono1, Telefono2, EMail) VALUES('" . $_POST["Nombre"] . "', '" . $_POST["Calle"] . "'," . $_POST["NInt"] . "," . $_POST["NExt"] . ",'" . $_POST["Colonia"] . "','" . $_POST["Ciudad"] . "','" . $_POST["Estado"] . "','" . $_POST["Pais"] . "'," . $_POST["CP"] . "," . $_POST["Telefono1"] . "," . $_POST["Telefono2"] . ",'" . $_POST["EMail"] . "');");
- //Get last inserted record (to return to jTable)
- $result = mysql_query("SELECT * FROM clientes WHERE ID_Cliente = LAST_INSERT_ID();");
- $row = mysql_fetch_array($result);
- //Return result to jTable
- $jTableResult = array();
- $jTableResult['Result'] = "OK";
- $jTableResult['Record'] = $row;
- print json_encode($jTableResult);
- }
- //Updating a record (updateAction)
- else if($_GET["action"] == "update")
- {
- //Update record in database
- $result = mysql_query("UPDATE clientes SET Nombre = '" . $_POST["Nombre"] . "', Calle= '" . $_POST["Calle"] . "', NExt= " . $_POST["NExt"] . ", NInt= " . $_POST["NInt"] . ", Colonia= '" . $_POST["Colonia"] . "', Ciudad= '" . $_POST["Ciudad"] . "', Estado= '" . $_POST["Estado"] . "', Pais= '" . $_POST["Pais"] . "',CP= " . $_POST["CP"] . ", Telefono1= " . $_POST["Telefono1"] . ", Telefono2= " . $_POST["Telefono2"] . ", EMail= '" . $_POST["EMail"] . "' WHERE ID_Cliente = " . $_POST["ID_Cliente"] . ";");
- //Return result to jTable
- $jTableResult = array();
- $jTableResult['Result'] = "OK";
- print json_encode($jTableResult);
- }
- //Deleting a record (deleteAction)
- else if($_GET["action"] == "delete")
- {
- //Delete from database
- $result = mysql_query("DELETE FROM clientes WHERE ID_Cliente = " . $_POST["ID_Cliente"] . ";");
- //Return result to jTable
- $jTableResult = array();
- $jTableResult['Result'] = "OK";
- print json_encode($jTableResult);
- }
- //Close database connection
- mysql_close($con);
- }
- catch(Exception $ex)
- {
- //Return error message
- $jTableResult = array();
- $jTableResult['Result'] = "ERROR";
- $jTableResult['Message'] = $ex->getMessage();
- print json_encode($jTableResult);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement