Skip to content
Advertisement

how to get price from database in php and javascript

I am new in PHP and javascript I am creating an order form that has four fields customer, product, price, amount what I want. when I select a product it will get the last order price of the selected customer if he already exists. if the new customer then gets the price from the product_list table. here is my code.

JavaScript

Advertisement

Answer

okay at the first i dont know your customer & product_list schema table, so i just i create table order only with information at your code, and i think you need to avoid named table with function already exist at mysql, so i rename table order to order_list, the schema will like this table customer_list

JavaScript

table product_list

JavaScript

table order_list

JavaScript

i create 2 file, first is form.php , its include code you create and add javascript to get the last order customer from table order_list with ajax. the code will like this

JavaScript

the function will fired when id product and customer_id at select option change, at the first its 3 var , customer_id , product_id , and price it will get the selected value from selected option customer_id and product and var price will save data-price from selected option product . and i use ajax to get the last data from order_list it will send var customer_id,product_id to the second form getorder.php

getorder.php will like this

JavaScript

that code above is for get the last data from table order_list and the result will parse to json, at the ajax if succes get data success: function(response) it will check if the response null or not, if null the input field qty and amount will be empty and price input field value filled with var price , if the response not null the data input field will filled with data you get. and at the function $("#qty,#price").change(function(){}); it will calculate the input field amount when data at input field qty or price changed

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement