MySQL PHP搜索数据库并显示输出


MySQL PHP search database and display output

用户输入-<input type="text" name="name">

我想接受用户输入的"姓名",并显示与该客户相关的交易ID,以及歌曲名称和艺人名称

我的数据库是这样的

  • 艺术家
  • 客户-姓氏或此处的"name"
  • 歌曲
  • transactions-trans_ID和customer_ID在此处
  • transaction_details-trans_ID和song_ID在此处

我一直在使用的查询结构如下

$q="SELECT customers.last_name, FROM customers LEFT JOIN transactions ON customers.customer_ID = transactions.customer_ID LEFT JOIN songs ON songs.song_ID = transaction_details.song_ID WHERE customers.last_name LIKE '$lname%' AND customers.first_name LIKE '$name%";

$name = $_POST['name'];

我希望它显示:transaction_ID+歌曲名称+艺人名称

  • 与被搜索的客户有关

有人知道我怎样才能达到我所需要的吗?非常感谢。

You can use jquery Autocomplete or go through the url :-http://jqueryui.com/autocomplete/ 
    <script>
        $(function() {
            function log(message) {
                $("<div>").text(message).prependTo("#log");
                $("#log").scrollTop(0);
            }
            $("#search").autocomplete({
                minLength: 1,
                source: 'action.php',
            })
                    .autocomplete("instance")._renderItem = function(ul, item) {
                if (item.fname) {
                    if (item.photo) {
                        return $("<li style='padding: 0px;'' href='/user-profile?user=" + item.id + "'>")
                                .append("<a style='margin: 0px; display: block; width: 100%; height: 100%;' href='/user-profile?user=" + item.id + "'><img src = '{{CLIENT_ROOT_PATH}}/assests/img/profile/thumbnail-130x130/" + item.photo + "' width =30 />   " + item.fname + " " + item.lname + "</a>")
                                .appendTo(ul);
                    }
                } else {
                    return $("<li>")
                            .append("<a href='#'> No result found</a>")
                            .appendTo(ul);
                }
            };
        });
    </script>

    And here the HTML :-
    <input type="text" placeholder="Search" class="form-control" id="search">

    on action.php page return the required value in array form.