我需要知道使用PHP&Mysql,Ajax,Jsone给我那家公司的最后价格。
这是MySQl上的代码
SELECT tbl_order_item.order_id,tbl_order_item.item_name,tbl_order_item.order_item_price ,tbl_order.order_receiver_name FROM tbl_order_item INNER JOIN tbl_order ON tbl_order_item.order_id = tbl_order.order_id WHERE tbl_order.type="PROFORMA INVOICE" GROUP BY tbl_order_item.item_name order BY tbl_order.order_receiver_name ASC
在Mysql数据库后端中,我得到了结果,但是如何在前台自动显示时运行相同的过程?My database
答案 0 :(得分:0)
我曾在PHP尝试过Code,但是我只有一个产品名称,只有我的代码在这里 index.php 脚本
<script type="text/javascript">
$(document).ready(function(){
$(document).on('keydown', '.orderreceiver', function() {
var id = this.id;
var splitid = id.split('_');
var index = splitid[1];
$( '#'+id ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "get_cprice.php",
type: 'post',
dataType: "json",
data: {
search: request.term,request:1
},
success: function( data ) {
response( data );
}
});
},
select: function (event, ui) {
$(this).val(ui.item.label); // display the selected text
var userid = ui.item.value; // selected id to input
// AJAX
$.ajax({
url: 'get_cprice.php',
type: 'post',
data: {userid:userid,request:2},
dataType: 'json',
success:function(response){
var len = response.length;
if(len > 0){
var id = response[0]['id'];
var itemname = response[0]['itemname'];
//var description = response[0]['description'];
//var suom = response[0]['suom'];
//var cost = response[0]['cost'];
//var stock = response[0]['stock'];
//var category = response[0]['category'];
document.getElementById('itemname_'+index).value = itemname;
//document.getElementById('description_'+index).value = description;
//document.getElementById('suom_'+index).value = suom;
//document.getElementById('cost_'+index).value = cost;
//document.getElementById('stock_'+index).value = stock;
//document.getElementById('category_'+index).value = category;
}
}
});
return false;
}
});
});
// Add more
$('#addmore').click(function(){
// Get last id
var lastname_id = $('.tr_input input[type=text]:nth-child(1)').last().attr('id');
var split_id = lastname_id.split('_');
// New index
var index = Number(split_id[1]) + 1;
// Create row with input elements
var html = "<tr class='tr_input'><td><input type='text' class='orderreceiver' id='orderreceiver_"+index+"' placeholder=''></td><input type='text' class='itemname' id='itemname_"+index+"'></td></tr>";
// Append data
$('tbody').append(html);
});
});
</script>
结果单个公司项目仅显示一个问题 enter image description here