DB_PRODUCTS Product GetList ImgIDs Array foreach DB_PRODUCTS as produc

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$DB_PRODUCTS = Product::GetList();
$ImgIDs = Array();
foreach( $DB_PRODUCTS as $product ){
if ( sizeof( $product[ 'IMAGES' ] ) ){
$ImgIDs[] = array_shift( $product[ 'IMAGES' ] );
}
}
global $DB;
$query = "SELECT * FROM images WHERE ID='".implode( "' OR ID='" , $ImgIDs )."'; ";
$res = $DB->Query( $query );
$DB_IMGs = Array();
while( $img = $DB->FetchArray( $res ) ){
$DB_IMGs[ $img[ 'ID' ] ] = $img;
}
foreach( $DB_PRODUCTS as $pKey => $product ){
if ( sizeof( $product[ 'IMAGES' ] ) ){
$buffer = Array();
foreach( $product[ 'IMAGES' ] as $imgKey => $imgID ){
$buffer[ $imgKey ] = $DB_IMGs[ $imgID ];
}
$DB_PRODUCTS[ $pKey ][ 'IMAGES' ] = $buffer;
}
}