[英]How do I get the correct information out of my objects/ array with php / mysql?
I'm not a expert in programming but I want to set my old website over to new design and herefor I want to re-use my old code (slightly adjusted). 我不是编程专家,但是我想将旧网站设置为新设计,因此我想重用旧代码(略作调整)。
With the following function I get all artist information and guitar songs written. 使用以下功能,我可以编写所有艺术家信息和吉他歌曲。 To display in a table.
显示在表格中。
but the artist information (aArtist) is no problem but the song information is not working correctly. 但是艺术家信息(aArtist)没问题,但是歌曲信息无法正常工作。 I think I'm not far away but what should/could i try to make it work.
我想我并不遥远,但是我应该/应该设法使它起作用。
When printing (var_dump) the $aArtist I do get all information, its now hot to manage this. 当打印(var_dump)$ aArtist时,我确实获得了所有信息,现在管理该信息非常热门。
Thanks for all suggestions. 感谢您的所有建议。 Jan
一月
function getArtistBySeoName($sSeoName,$sSortColumn,$sSortDirection,$sWhere)
{
$sWhereAdditions = "";
if($sWhereAdditions == "" && $sWhere != "")
{
$sWhereAdditions = " WHERE ".$sWhere;
}
$sSeoName = str_replace("'", "", $sSeoName);
$sQuery = "SELECT * FROM artist a
LEFT JOIN artist_info ai ON a.artist_id = ai.artist_info_artist_id
WHERE artist_seoname = '".$sSeoName."'
".$sWhereAdditions." ";
$oQueryResult = query($sQuery);
$oArtist = $oQueryResult->fetch_assoc();
$aSongs = array();
$sQuery2 = "SELECT s.song_id,s.song_name,a.*,aa.*,st.*,ss.*,d.* FROM song s
LEFT JOIN song_type st ON s.song_song_type_id = st.song_type_id
LEFT JOIN song_style ss ON s.song_style_id = ss.song_style_id
LEFT JOIN song_status sst ON sst.song_id = s.song_id
LEFT JOIN artist_album aa ON s.song_album_id = aa.artist_album_id
LEFT JOIN download d ON s.song_id = d.download_song_id inner join artist a on a.artist_id=s.song_artist_id
WHERE s.song_artist_id = ".$oArtist[artist_id]." and (sst.status=1 or sst.status=2 or sst.status=3) ORDER BY ".$sSortColumn." ".$sSortDirection;
$oQueryResult2 = query($sQuery2);
$i=0;
while($oSong = $oQueryResult2->fetch_assoc())
{
$i++;
$aSongs[]=$oSong;
}
$oArtist[songs] = $aSongs;
$aAlbums = array();
$sQuery3 = "SELECT * FROM artist_album aa
INNER JOIN song s ON s.song_album_id = aa.artist_album_id
WHERE s.song_artist_id = ".$oArtist[artist_id]." GROUP BY aa.artist_album_id";
$oQueryResult3 = query($sQuery3);
while($oAlbum = $oQueryResult3->fetch_assoc())
{
$aAlbums[]=$oAlbum;
}
$oArtist[albums] = $aAlbums;
$aImages = array();
$sQuery3 = "SELECT * FROM artist_images ai
WHERE ai.artist_image_artist_id = ".$oArtist[artist_id]." ";
$oQueryResult3 = query($sQuery3);
while($oImage = $oQueryResult3->fetch_assoc())
{
$aImages[]=$oImage;
}
$oArtist[images] = $aImages;
$oArtist[songscount] = $i;
return $oArtist;
}
?>
<?
$sSeoName = $route[2];
$sSortColumn ="song_name";
$sSortDirection="ASC";
$sWhere = "";
$aArtist = getArtistBySeoName($sSeoName,$sSortColumn,$sSortDirection,$sWhere);
var_dump($aArtist);
Below here the code where I am trying to print the values. 在下面的代码中,我尝试打印值。 This is where it goes wrong probably.
这可能是哪里出错了。
<?
foreach($aArtist as $oSong)
{
//print $aArtist[song_name];
switch($oSong[song_type_name])
{
case "CRD":
$sPagename = CHORDSPAGE;
break;
case "TAB":
$sPagename = TABPAGE;
break;
case "BTAB":
$sPagename = BTABPAGE;
break;
case "LYRIC":
$sPagename = LYRICSPAGE;
break;
case "PTB":
$sPagename = PTBPAGE;
break;
case "GPR":
$sPagename = GPRPAGE;
break;
}
?> ?>
<tr>
<td><span itemprop="name"><a href="/<?=$sPagename?>/<?=$oSong[artist_seoname]?>/<?=$oSong[song_seoname]?>"><? echo ucwords($oSong->song_name);?></a><span><meta itemprop="url" content ="http://www.gitaartabs.nl/<?=$sPagename?>/<?=$oSong[artist_seoname]?>/<?=$oSong[song_seoname]?>"><meta itemprop="duration" content="PT2M30S"></td>
<td class=""><?=ucfirst($oSong[song_type_name])?></td>
<td class="hidden-sm"><?=ucfirst($oSong[artist_album_name])?></td>
<td class="hidden-sm"><?=ucfirst($oSong[artist_album_year])?></td>
<td class="hidden-sm"><?=ucfirst($oSong[song_style_name])?></td>
<td><em><?=ucfirst($oSong[download_amount])?></em></td>
<td><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-half-o"></i></td>
</tr>
</tbody>
</table>
<!--End Basic Table-->
I fixed this by using a foreach(song as songval) { } code 我通过使用foreach(歌曲作为Songval){}代码来解决此问题
thanks all for your help 感谢你的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.