Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数据库中下拉搜索,获取不同型号/品牌的图像并显示_Php_Html_Mysql_Ajax - Fatal编程技术网

Php 从数据库中下拉搜索,获取不同型号/品牌的图像并显示

Php 从数据库中下拉搜索,获取不同型号/品牌的图像并显示,php,html,mysql,ajax,Php,Html,Mysql,Ajax,我的问题是显示一个与mysql结果关联的图像。。。假设结果的ID=250,Name=brand.model,那么我需要一段代码在服务器上的文件夹中搜索名称为ID_brand.model.jpg的图像 数据库结构是id、master和name。当用户从下拉列表中选择品牌+型号时,它应该从文件夹中获取图像,也可以从数据库中获取图像,现在哪一个更好,图像都有唯一的名称,应该作为零件名称进行呼应 图片有助于理解我的意思 这是我编写的pastebin代码。 非常感谢您的帮助。首先,您需要绑定select

我的问题是显示一个与mysql结果关联的图像。。。假设结果的ID=250,Name=brand.model,那么我需要一段代码在服务器上的文件夹中搜索名称为ID_brand.model.jpg的图像

数据库结构是id、master和name。当用户从下拉列表中选择品牌+型号时,它应该从文件夹中获取图像,也可以从数据库中获取图像,现在哪一个更好,图像都有唯一的名称,应该作为零件名称进行呼应

图片有助于理解我的意思

这是我编写的pastebin代码。


非常感谢您的帮助。

首先,您需要绑定select的更改事件,以将名称发送到搜索文件的函数,然后将文件附加到DOM:

Javascript-Ajax PHP search_images.PHP
你不能做什么?不管怎样,请看:我对PHP/MySQL/JS没有太多经验,所以我在编写代码时遇到了麻烦。你想让我们免费为你编写代码吗?太棒了。不是真的,只是一点开始的帮助。@sknnndz只是一个问题,如果你选择东西,它可能会返回几个图像?是的,它应该找到模型的所有图像。例如,用户选择Alfa Romeo->Giulia,它从文件夹中获取所有图像,该文件夹包含该模型的所有图像。哦,所以你确实需要一些ajax来完成这项工作,在这种情况下,它将找到具有此文件名模式的所有图像:*u alfaromero.giulia.jpg?例如:是的,就是这样@axel-a-grazx嗨,伙计,我一直在努力让代码正常工作,但我遇到了一点问题。你能帮我更多吗?
// Every time a category is selected we request the files
$('#category').on('change', function() {
    // If we have an element with images loaded, lets delete it
    var searchResult = $("#search-result").empty();
    // Now we serialize the form data, add an id to the form
    var searchBrand = $('#gender').find('option:selected').text();
    var searchModel = $('#category').find('option:selected').text();
    var fileName = searchBrand + '.' + searchModel + '.jpg';
    var searchData = { filename: fileName }
    // Now we create the ajax request with the form data
    var request = $.getJSON('search_images.php', searchData);
    // If the request success we show the images
    request.done(function(data) {
        // For each image found we add a new image to the DOM
        $.each(data, function(index, image_uri) {
            // First let's create the image element
            var img = $("<img>", {
                "class": "result-image",
                "src": image_uri
            });
            // Then we append it to the DOM
            searchResult.append( img );
        });
    });
    // If the search fails, we notify that no results were found
    request.fails(function() {
        alert('No results found');
    });
});
<?
// Get the file name
$filename = $_GET['filename'];
// Find all the images
$images = glob("images/file/path/*_{$filename}");
// Return the images as json
echo json_encode($images);