教程: 在XoopsTube中突出显示非空字母列表

发布者:Mamba在2013/6/17 0:40:00 阅读次数:6246
In XoopsTube we have a visual alphabetical listing of videos, so if you would like to see all videos starting with "B" you would click on the image with "B". Unfortunately, this is not the most user-friendly feature, because we don't know if there is anything under "B". So we needed to indicate the existence of videos by a changed background icon, as you can see below: Resized Image The plan was to: 1) build an array of unique alphabet letters that have videos in the database 2) as we render the alphabet icons, check for each letter/digit if it is also in the above array, and if yes, change the icon image to the green one XoopsTube renders the images in the function xoopstube_letters() located in /include/functions.php As first we needed to extract the unique letters from the database and create the array
$distinctDbLetters_arr = array();
    
$sql 'SELECT DISTINCT (UPPER(LEFT(title, 1))) AS letter FROM ' $xoopsDB->prefix('xoopstube_videos') ;
    if (
$result $xoopsDB->query($sql)) {
        while (
$row $xoopsDB->fetchArray($result)) {
            
$distinctDbLetters_arr[] = $row['letter'];
        }
    }
    unset(
$sql);
其次,我们想要检查每个字母和数字是否在数据库中有所表示
if (in_array($ltr$distinctDbLetters_arr)) {
            
$letterchoice
                
.= '        } else {
            
$letterchoice
                
.= '
        }
.xoopstube_letters_green {
    
background-imageurl(images/icon/backgnd_green.png);
}
未来的任务:- 缓存(1)中创建的数组,以避免每次都从数据库中读取它,并且只在添加新视频时更新它。本教程的主要信息是通过视觉指示信息的状态使我们的模块更加用户友好。像往常一样,如果有人有更好的方法实现它,请与我们分享!