Showing fields of two tables in the same application

In this tutorial we will show how to show and manipulate data of two different tables in the same application.

We will use tables that represent orders and customers, where each order has its customers. we will show customers data in the form application of order.

First we will create a form based application in the first table, orders table.

In this application we have to create fields to show the values of the customer from the Customers table.

Showing data from the second table

 

Will create a PHP method called showCustomer, include the code below:

 

$ Customer = {customerid};

sc_lookup (customer, “SELECT

companyname, ContactName, stateid, city, address, CreditLimit

FROM

customers

WHERE

customerid = ‘$ customer’ “);

 

if (! empty ({client})) {

 

CompanyName {} = {client [0] [0]};

ContactName {} = {client [0] [1]};

Stateid {} = {client [0] [2]};

{City} = {client [0] [3]};

{Address} = {client [0] [4]};

CreditLimit {} = {client [0] [5]};

}

 

Here we are using the macro sc_lookup () with this macro can retrieve database records running a SELECT on any table in the database.

This macro have 2 parameters, the first is a dataset that retrieve the values. you can give any name for this dataset, in this example we will name it customer. The second parameter we reported a String with the sql SELECT statement to retrieve the values.

 

This dataset is a PHP matrix where we have two positions in brackets. In the first bracket inform the row of the matrix, on the second we inform the column.

In the onLoad event call our ‘carregarCliente’ method by entering the following command line:

carregarCliente();

 

We change the client field of the formulary to select type and we create a OnChange Event on that field calling the method ‘carregarCliente’, including the following line:

carregarCliente();

 

Changing records of both tables at same time

 

To change the records of the second table (Client), put the following code on the onBeforUpdate Event.

 

$customerid = {customerid};

$companyname = {companyname};

$contactname = {contactname};

$stateid = {stateid};

$city = {city};

$address = {address};

$creditlimit = {creditlimit};

 

if((!empty($customerid)) && (!empty($companyname)) && (!empty($contactname)) && (!empty($stateid)) &&

(!empty($city)) && (!empty($address)) && ($creditlimit >= 0)){

 

sc_exec_sql(“UPDATE

customers

SET companyname = ‘$companyname’, contactname = ‘$contactname’,

stateid = ‘$stateid’, city = ‘$city’, address = ‘$address’, creditlimit = ‘$creditlimit’

WHERE

customerid = ‘$customerid'”);

 

}else{

sc_error_message(“Have Blank Fields.”);

}

 

Here we are using the macro sc_exec_sql, with it we can use SQL statements, for example a INSERT, UPDATE, DELETE.

On the example that we did it’s using the table according to the changes done.

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.