我有一个查询,它会提取新闻故事,然后附加与特定故事相关的任何照片。这一切都很好,但我最近添加了一个功能来提取与故事相关的视频,它会导致显示重复的图像或视频链接。
例如,我有一个包含 3 张图片和 1 个视频的新闻报道。目前它会在每张图片旁边发布一个视频,因此它会显示 3 次。我真正想要展示的是新闻报道,然后是任何图片,然后是任何视频。
这是php
$sLastStory = '';
foreach ($result AS $row)
{
$sStory = $row['headline'] . $row['story'];
if (strcasecmp($sStory, $sLastStory) != 0)
{
if (!empty($sLastStory))
{
print('<hr>' . PHP_EOL);
}
$sLastStory = $sStory;
printf('<h2>%s</h2>' . PHP_EOL, $row['headline']);
printf('<a href="parknews.php?park_id=%s">
<h3>%s</a> - %s</h3>' . PHP_EOL, $row['park_id'], $row['name'], $row['Displaydate']);
printf('<p>%s</p>' . PHP_EOL, $row['story']);
}
if(!empty($row['url'])){
printf('
<a href="/images/%s%s.jpg" rel="lightbox[%s]" title="%s - Credit - %s" >
<img src="/images/%s%s-thumb.jpg" style="min-height: 200px; min-width: 200px" alt="%s"/></a>' . PHP_EOL, $row['url'], $row['alt'], $row['headline'], $row['description'],$row['credit'], $row['url'], $row['alt'], $row['alt'] );
}
if(!empty($row['location'])){
printf('<iframe width="640" height="360" src="%s" frameborder="0" allowfullscreen></iframe>' . PHP_EOL, $row['location'] );
}
}
我对 PHP 不是很好,只是复制了这一部分:
if(!empty($row['url'])){
printf('
<a href="/images/%s%s.jpg" rel="lightbox[%s]" title="%s - Credit - %s" >
<img src="/images/%s%s-thumb.jpg" style="min-height: 200px; min-width: 200px" alt="%s"/></a>' . PHP_EOL, $row['url'], $row['alt'], $row['headline'], $row['description'],$row['credit'], $row['url'], $row['alt'], $row['alt'] );
}
然后将其粘贴在下面,但将其更改为视频查询而不是图像。任何想法如何修复它以正确显示?谢谢
编辑:这是查询
try
{
$sql = 'SELECT headline, story, DATE_FORMAT(date, "%d-%M-%Y") AS Displaydate, name, logo, tpf_parks.park_id, url, alt, description, credit, location
FROM tpf_news
INNER JOIN tpf_parks ON tpf_news.park_id = tpf_parks.park_id
LEFT JOIN tpf_images ON tpf_news.news_id = tpf_images.news_id
LEFT JOIN tpf_videos ON tpf_news.news_id = tpf_videos.news_id
ORDER BY date DESC' ;
$result = $pdo->query($sql);
}