Changeset 8802 for trunk/include/functions_category.inc.php
- Timestamp:
- Jan 20, 2011, 2:32:34 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_category.inc.php
r8728 r8802 496 496 } 497 497 498 /** 499 * Find a random photo among all photos below a given album in the tree (not 500 * only photo directly associated to the album but also to sub-albums) 501 * 502 * we need $category['uppercats'], $category['id'], $category['count_images'] 503 */ 504 function get_random_image_in_category($category) 505 { 506 $image_id = null; 507 if ($category['count_images']>0) 508 { 509 $query = ' 510 SELECT image_id 511 FROM '.CATEGORIES_TABLE.' AS c 512 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id 513 WHERE (c.id='.$category['id'].' OR uppercats LIKE \''.$category['uppercats'].',%\')' 514 .get_sql_condition_FandF 515 ( 516 array 517 ( 518 'forbidden_categories' => 'c.id', 519 'visible_categories' => 'c.id', 520 'visible_images' => 'image_id', 521 ), 522 "\n AND" 523 ).' 524 ORDER BY '.DB_RANDOM_FUNCTION.'() 525 LIMIT 1 526 ;'; 527 $result = pwg_query($query); 528 if (pwg_db_num_rows($result) > 0) 529 { 530 list($image_id) = pwg_db_fetch_row($result); 531 } 532 } 533 534 return $image_id; 535 } 498 536 ?>
Note: See TracChangeset
for help on using the changeset viewer.