как показать авто-детали о компании, используя php & mysql Ajax, Jsone - PullRequest
0 голосов
/ 21 мая 2019

Мне нужно знать последнюю цену продукта, когда в последний раз мне давали эту компанию, используя 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 Database Backend я получил результаты, но как запустить тот же процесс на автовыставке? Моя база данных

1 Ответ

0 голосов
/ 21 мая 2019

Я попробовал код на PHP, но я получил только одно название продукта, только мои коды здесь 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>

В результате один элемент компании показывает только один, который является проблемой введите описание изображения здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...