我想有艺术家(歌曲艺术家)的形象,可在最近的歌曲查看。
以下是我猜您在回答时可能需要的php文件和数据库表:
(如果有人能这么快地教我如何使用查询命令在交叉使用表(而不仅仅是一行表)的情况下选择这样的数据,我会很高兴的。如果没有plz,请更改代码以便查看艺术家图片)
以下是帮助php代码

<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

class modMusColRecentlyAddedSongsHelper
{


function getSongs(&$params)
{
    global $mainframe;
    $_db    = & JFactory::getDBO();
    $model      = modMusColRecentlyAddedSongsHelper::getModel();

        $limit = $params->get( 'n_songs', 5 );

        if($params->get( 'artist_id' )) $where_clause[] = " s.artist_id = " . $params->get( 'artist_id' ) . " " ;

        if ($params->get( 'genre_id' )) {
            $genre_id = $params->get( 'genre_id' );
            $model->getDescendantsId($genre_id);
            $descendants = $model->descendantsId;
            $descendants[] = $genre_id ;
            $genre_clause = ' ( s.genre_id = ' . implode(' OR s.genre_id = ',$descendants) . ' ) ';
            $where_clause[] = $genre_clause;
        }


            //$where_clause[] = ' ra.type = "song" ';
            $where_clause = (count($where_clause) ? ' WHERE '.implode(' AND ', $where_clause) : '');

            $query =    ' SELECT s.*, ar.artist_name,al.name as album_name, AVG(ra.points) as points FROM #__muscol_songs as s '.
                        ' LEFT JOIN #__muscol_albums as al ON al.id = s.album_id '.
                        ' LEFT JOIN #__muscol_artists as ar ON ar.id = s.artist_id '.
                        ' LEFT JOIN #__muscol_ratings as ra ON ra.album_id = s.id AND ra.type = "song" '.
                        $where_clause .
                        ' GROUP BY s.id ' .
                        ' ORDER BY s.added DESC '.
                        ' LIMIT '. $limit;

                        //echo $query;die;


        $_db->setQuery( $query );
        $recent_songs = $_db->loadObjectList();

        //print_r($query);die;

        return $recent_songs;

}

function getModel()
{
    if (!class_exists( 'ArtistsModelSearch' ))
    {
        // Build the path to the model based upon a supplied base path
        $path = JPATH_SITE.DS.'components'.DS.'com_muscol'.DS.'models'.DS.'search.php';
        $false = false;

        // If the model file exists include it and try to instantiate the object
        if (file_exists( $path )) {
            require_once( $path );
            if (!class_exists( 'ArtistsModelSearch' )) {
                JError::raiseWarning( 0, 'Model class ArtistsModelSearch not found in file.' );
                return $false;
            }
        } else {
            JError::raiseWarning( 0, 'Model ArtistsModelSearch not supported. File not found.' );
            return $false;
        }
    }

    $model = new ArtistsModelSearch();

    return $model;
}

}

下面是default.php代码
<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<?php
if($params->get( 'Itemid' )) $itemid = "&Itemid=".$params->get( 'Itemid' );
   else $itemid = "";
   $document =& JFactory::getDocument();
   $document->addStyleSheet(JURI::base(true).'/modules/mod_muscol_recently_added_songs/tmpl/recently_added_songs.css');
?>

 <div class='recently_added_songs'>
 <table border='0' cellpadding='0' cellspacing='0' width="100%">
 <thead>
 <tr>
  <th> <?php echo JText::_( 'آهنگ' ); ?> </th>
   <? if($params->get('show_album')){ ?><th> <?php echo JText::_( 'آلبوم' ); ?> </th><? } ?>
  <? if($params->get('show_artist')){ ?><th> <?php echo JText::_( 'خواننده' ); ?> </th><? } ?>
  <? if($params->get('show_rating')){ ?><th> <?php echo JText::_( 'امتياز' ); ?> </th><? } ?>
</tr>
</thead>
<?php
 $n = 0;
  for ($j=0, $m=count( $songs ); $j < $m; $j++) {
 $song = $songs[$j];
$link= JRoute::_( 'index.php?option=com_muscol&view=song&id='. $song->id . $itemid);
$link_album= JRoute::_( 'index.php?option=com_muscol&view=album&id='. $song->album_id . $itemid);
$link_artist= JRoute::_( 'index.php?option=com_muscol&view=artist&id='. $song->artist_id . $itemid);

//$image = MusColHelper::createThumbnail($album->image, $album->name, $params->get('default_width'), $image_attr);
?>
 <tr class="tr_recent_songs <?php echo "row$n"; ?>">
  <td><a href="<?php echo $link; ?>"><?php echo $song->name; ?></a></td>
  <? if($params->get('show_album')){ ?><td><a href="<?php echo $link_album; ?>"><?php echo $song->album_name; ?></a></td><? } ?>
  <? if($params->get('show_artist')){ ?><td><a href="<?php echo $link_artist; ?>"><?php echo $song->artist_name; ?></a></td><? } ?>
  <? if($params->get('show_rating')){ ?><td><?php echo MusColHelper::show_stars($song->points,false,false,false,true);?></td><? } ?>
</tr>
<?php
$n = 1 - $n ;
}
?>
 </table>
</div>

数据库中的songs表(表名为songs)
id  album_id  num  disc_num  length  name  lyrics  artist_id  composer_id  filename  extension  review  songwriters  chords  genre_id  hits  buy_link  video  position  downloaded  user_id

数据库中的艺术家表(应从图片列读取艺术家图片)
id artist_name  image  review  letter  class_name  related  keywords  added  hits  country  picture  user_id  metakeywords  metadescription  city  years_active  url  genre_id

最佳答案

您已经在helper中查询了正确的表,因此-如果您显示的代码已经工作-您只需要返回额外的字段:

  $query =    ' SELECT s.*, ar.artist_name,al.name

变成
  $query =    ' SELECT s.*, ar.artist_name,ar.image as artistimage, al.name

然后在视图中:
<?php echo $song->artist_name; ?>

变成
<?php echo  $song->artist_name;
echo sprintf('<img src="%s" class="artistpic" />',$song->artistimage);
 ?>

10-08 07:52