在foreach中显示数据库中的图像

时间:2018-12-11 08:54:14

标签: php mysql

我尝试从桌子上拿图片  通过从“ products_category”中选择ID来选择“ products_category_images”。

我试图在foreach中使用foreach以及为它循环。

这是类处理代码:

function fetchCategoryTree($parent = 0, $spacing = '', $user_tree_array = '') {

    if (!is_array($user_tree_array))
        $user_tree_array = array();


    $fastQuery = fastQuery('SELECT `id` FROM `products_category` ORDER BY `id` DESC');

    foreach($fastQuery as $key => $values) {

        ## PICTURES ## 
        $sqlImage = "SELECT * FROM `products_category_images` WHERE `uniqueID` = '".$values['id']."' LIMIT 1"; 
        $resImage = mysql_query($sqlImage); 

    }
                    $sql = "SELECT * FROM `products_category_translate` WHERE `parentID` = $parent AND `language` = '".lang()."'";
                    $query = mysql_query($sql);

                    while (($row = mysql_fetch_object($query))||($row = mysql_fetch_object($resImage))) {
                        $user_tree_array[] = array("id" => $row->id, "image" => $spacing . $row->image, "uniqueID" => $row->uniqueID, "title" => $spacing . $row->title);
                        $user_tree_array = fetchCategoryTree($row->uniqueID, $spacing . '-- ', $user_tree_array);
                    }

    return $user_tree_array;
}

在这里我得到结果:

        $categoryList = fetchCategoryTree();
        foreach($categoryList as $cl) { 
            echo '<a href="'.$g['url'].''.languageURL('0', 'products/'.$cl['uniqueID'].'/'.convertToURL($cl['title']).'.html').'"><img src="'.$g['url'].'uploads/products-category/'.$cl['image'].'" style=" width: 85px; height: 45px; display: inline;" class="img-responsive"> '.$cl['title'].'</a><br>';
            echo ''.$rowfastQuery['id'].'';
        }

我尝试在周期结束时获取ID并递增,但此操作不再起作用。

0 个答案:

没有答案