Playing Track Function
4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 26, 2010 (RSS)
By Joseph - November 25, 2010
I currently have a list of current tracks on my home page - http://www.socanews.com/index3.php which when a track is cliked goes to the folloing page - http://www.socanews.com/music/ however the track doesnt automatically play. what would i need to do to enable this function?
This is the current code for the track list on the home page:
<?php foreach ($toptracksRecords as $track): ?>
<?php @$artist = getArtist($track['artists']); ?>
<?php foreach ($track['upload'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<?php continue; ?>
<?php else: ?>
<?php if (@$artist[0]['image']): ?>
<img src="<?php echo @$artist[0]['image'][0]['urlPath']; ?>" width="75" border="0" style="float: left; padding-right: 2px;" />
<?php else: ?>
<?php endif; ?>
<a href="./music" class="articleContentBold"><?php echo $track['title'] ?></a>| <?php echo $track['artists'] ?><br/>
<span class="eventIndexMore"><?php echo $track['country'] ?> | <?php echo $track['album_riddim'] ?> | <?php echo $track['year'] ?> | <?php echo $track['plays']; ?> Plays</span><br/>
<div style="background-color: #C0DEED; height: 1px; width: 100%; margin: 10px 0 5px 0;"> </div>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach ?>
This is the current code for the track list on the home page:
<?php foreach ($toptracksRecords as $track): ?>
<?php @$artist = getArtist($track['artists']); ?>
<?php foreach ($track['upload'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<?php continue; ?>
<?php else: ?>
<?php if (@$artist[0]['image']): ?>
<img src="<?php echo @$artist[0]['image'][0]['urlPath']; ?>" width="75" border="0" style="float: left; padding-right: 2px;" />
<?php else: ?>
<?php endif; ?>
<a href="./music" class="articleContentBold"><?php echo $track['title'] ?></a>| <?php echo $track['artists'] ?><br/>
<span class="eventIndexMore"><?php echo $track['country'] ?> | <?php echo $track['album_riddim'] ?> | <?php echo $track['year'] ?> | <?php echo $track['plays']; ?> Plays</span><br/>
<div style="background-color: #C0DEED; height: 1px; width: 100%; margin: 10px 0 5px 0;"> </div>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach ?>
Re: [socanews] Playing Track Function
By Chris - November 25, 2010
Hi socanews,
Could you please post the complete PHP source code for your list page and music page?
Could you please post the complete PHP source code for your list page and music page?
All the best,
Chris
Chris
Re: [chris] Playing Track Function
By Joseph - November 25, 2010
Hi Chris
this si the code that sits at the topof the php page:
<?php
require_once "/var/www/vhosts/socanews.com/httpdocs/cmsAdmin/lib/viewer_functions.php";
function string_limit_words($string) {
$words = explode(' ', $string);
return implode(' ', array_slice($words, 0, 10));
}
if (@$_REQUEST['ajaxnum']) { ajaxPlayCount(); }
function ajaxPlayCount() {
global $TABLE_PREFIX;
$num = mysql_real_escape_string(@$_REQUEST['ajaxnum']);
$currentplaysquery = mysql_query("SELECT plays FROM {$TABLE_PREFIX}videos WHERE num = $num LIMIT 1");
$currentplays = mysql_fetch_assoc($currentplaysquery);
$newplays = $currentplays['plays'] + 1;
mysql_query("UPDATE {$TABLE_PREFIX}videos SET plays = '$newplays' WHERE num = $num LIMIT 1");
exit;
}
function getArtist($artistname) {
$artistname = mysql_real_escape_string(trim($artistname));
list($artist, $blogMetaData) = getRecords(array(
'tableName' => 'artists',
'limit' => '1',
'where' => "title = '$artistname'",
'allowSearch' => '0',
));
return $artist;
}
function getDependentRecordTitle($table, $num) {
global $TABLE_PREFIX;
$num = mysql_real_escape_string($num);
$table = mysql_real_escape_string($table);
$query = mysql_query("SELECT title FROM {$TABLE_PREFIX}$table WHERE num = $num LIMIT 1");
$row = mysql_fetch_assoc($query);
return $row['title'];
}
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'limit' => '4',
'orderBy' => 'createdDate DESC',
'allowSearch' => '0',
));
list($carnivalsRecords, $carnivalsMetaData) = getRecords(array(
'tableName' => 'carnivals',
'limit' => '1',
'where' => 'startdate > NOW()',
'orderBy' => 'startdate ASC',
'allowSearch' => '0',
));
$carnival = $carnivalsRecords[0];
list($extraCarnivalRecords, $carnivalsMetaData) = getRecords(array(
'tableName' => 'carnivals',
'limit' => '2',
'offset' => '1',
'where' => 'startdate > NOW()',
'orderBy' => 'startdate ASC',
'allowSearch' => '0',
));
list($competitionsRecords, $competitionsMetaData) = getRecords(array(
'tableName' => 'competitions',
'limit' => '3',
'orderBy' => 'createdDate DESC',
'allowSearch' => '0',
));
list($toptracksRecords, $toptracksMetaData) = getRecords(array(
'tableName' => 'tracks',
'limit' => '10',
'orderBy' => 'createdDate DESC',
));
list($featuredartistRecords, $featuredartistMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '1',
'where' => "category LIKE '%featured%' AND category LIKE '%artist%'",
'orderBy' => 'createdDate DESC',
'allowSearch' => '0',
));
@$featuredartist = $featuredartistRecords[0];
list($eventsRecords, $eventsMetaData) = getRecords(array(
'tableName' => 'events',
'limit' => '3',
'where' => 'date > DATE_SUB(NOW(), INTERVAL 8 HOUR) AND date < DATE_ADD(NOW(), INTERVAL 2 WEEK)',
'orderBy' => 'date ASC',
'allowSearch' => '0',
));
list($videoRecords, $videoMetaData) = getRecords(array(
'tableName' => 'videos',
'orderBy' => 'createdDate DESC',
'limit' => '3',
'allowSearch' => '0',
));
list($newssliderRecords, $newssliderMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '2',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category NOT LIKE '%features%' AND category LIKE '%news%'",
'allowSearch' => '0',
));
list($featuredRecords, $featuredMetaData) = getRecords(array(
'tableName' => 'artists',
'limit' => '1',
'allowSearch' => '0',
));
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '3',
'offset' => '2',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category NOT LIKE '%features%' AND category LIKE '%news%'",
'allowSearch' => '0',
));
$newsnums = '';
foreach ($newsRecords as $news) {
$newsnums .= $news['num'] . ',';
}
$newsnums = trim($newsnums, ',');
list($featuresRecords, $featuresMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '3',
'offset' => '1',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category LIKE '%features%' AND num NOT IN ($newsnums)",
'allowSearch' => '0',
));
list($sliderfeaturesRecords, $sliderfeaturesMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '1',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category LIKE '%features%' AND num NOT IN ($newsnums)",
'allowSearch' => '0',
));
list($reviewsRecords, $reviewsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '3',
'offset' => '1',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category LIKE '%reviews%' AND num NOT IN ($newsnums)",
'allowSearch' => '0',
));
list($resultsRecords, $resultsMetaData) = getRecords(array(
'tableName' => 'news',
'offset' => '1',
'limit' => '3',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category LIKE '%results%' AND num NOT IN ($newsnums)",
'allowSearch' => '0',
));
list($sliderresultsRecords, $sliderresultsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '1',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category LIKE '%reviews%' AND num NOT IN ($newsnums)",
'allowSearch' => '0',
));
list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',
'limit' => '3',
'orderBy' => 'createdDate DESC',
'allowSearch' => '0',
));
list($jobRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'jobs',
'limit' => '3',
'orderBy' => 'createdDate DESC',
'allowSearch' => '0',
));
?>
the code for the track list is here:
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF"><div class="siHeaderBlueHome">Latest Soca Releases </div>
<div style="background-color: #C0DEED; height: 1px; width: 100%; margin: 0px 0 0px 0;"></div>
<div class="articleContent">
<?php foreach ($toptracksRecords as $track): ?>
<?php @$artist = getArtist($track['artists']); ?>
<?php foreach ($track['upload'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<?php continue; ?>
<?php else: ?>
<?php if (@$artist[0]['image']): ?>
<img src="<?php echo @$artist[0]['image'][0]['urlPath']; ?>" width="75" border="0" style="float: left; padding-right: 2px;" />
<?php else: ?>
<?php endif; ?>
<a href="./music" class="articleContentBold"><?php echo $track['title'] ?></a>| <?php echo $track['artists'] ?><br/>
<span class="eventIndexMore"><?php echo $track['country'] ?> | <?php echo $track['album_riddim'] ?> | <?php echo $track['year'] ?> | <?php echo $track['plays']; ?> Plays</span><br/>
<div style="background-color: #C0DEED; height: 1px; width: 100%; margin: 10px 0 5px 0;"> </div>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach ?>
</div></td>
</tr>
</table>
this si the code that sits at the topof the php page:
<?php
require_once "/var/www/vhosts/socanews.com/httpdocs/cmsAdmin/lib/viewer_functions.php";
function string_limit_words($string) {
$words = explode(' ', $string);
return implode(' ', array_slice($words, 0, 10));
}
if (@$_REQUEST['ajaxnum']) { ajaxPlayCount(); }
function ajaxPlayCount() {
global $TABLE_PREFIX;
$num = mysql_real_escape_string(@$_REQUEST['ajaxnum']);
$currentplaysquery = mysql_query("SELECT plays FROM {$TABLE_PREFIX}videos WHERE num = $num LIMIT 1");
$currentplays = mysql_fetch_assoc($currentplaysquery);
$newplays = $currentplays['plays'] + 1;
mysql_query("UPDATE {$TABLE_PREFIX}videos SET plays = '$newplays' WHERE num = $num LIMIT 1");
exit;
}
function getArtist($artistname) {
$artistname = mysql_real_escape_string(trim($artistname));
list($artist, $blogMetaData) = getRecords(array(
'tableName' => 'artists',
'limit' => '1',
'where' => "title = '$artistname'",
'allowSearch' => '0',
));
return $artist;
}
function getDependentRecordTitle($table, $num) {
global $TABLE_PREFIX;
$num = mysql_real_escape_string($num);
$table = mysql_real_escape_string($table);
$query = mysql_query("SELECT title FROM {$TABLE_PREFIX}$table WHERE num = $num LIMIT 1");
$row = mysql_fetch_assoc($query);
return $row['title'];
}
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'limit' => '4',
'orderBy' => 'createdDate DESC',
'allowSearch' => '0',
));
list($carnivalsRecords, $carnivalsMetaData) = getRecords(array(
'tableName' => 'carnivals',
'limit' => '1',
'where' => 'startdate > NOW()',
'orderBy' => 'startdate ASC',
'allowSearch' => '0',
));
$carnival = $carnivalsRecords[0];
list($extraCarnivalRecords, $carnivalsMetaData) = getRecords(array(
'tableName' => 'carnivals',
'limit' => '2',
'offset' => '1',
'where' => 'startdate > NOW()',
'orderBy' => 'startdate ASC',
'allowSearch' => '0',
));
list($competitionsRecords, $competitionsMetaData) = getRecords(array(
'tableName' => 'competitions',
'limit' => '3',
'orderBy' => 'createdDate DESC',
'allowSearch' => '0',
));
list($toptracksRecords, $toptracksMetaData) = getRecords(array(
'tableName' => 'tracks',
'limit' => '10',
'orderBy' => 'createdDate DESC',
));
list($featuredartistRecords, $featuredartistMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '1',
'where' => "category LIKE '%featured%' AND category LIKE '%artist%'",
'orderBy' => 'createdDate DESC',
'allowSearch' => '0',
));
@$featuredartist = $featuredartistRecords[0];
list($eventsRecords, $eventsMetaData) = getRecords(array(
'tableName' => 'events',
'limit' => '3',
'where' => 'date > DATE_SUB(NOW(), INTERVAL 8 HOUR) AND date < DATE_ADD(NOW(), INTERVAL 2 WEEK)',
'orderBy' => 'date ASC',
'allowSearch' => '0',
));
list($videoRecords, $videoMetaData) = getRecords(array(
'tableName' => 'videos',
'orderBy' => 'createdDate DESC',
'limit' => '3',
'allowSearch' => '0',
));
list($newssliderRecords, $newssliderMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '2',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category NOT LIKE '%features%' AND category LIKE '%news%'",
'allowSearch' => '0',
));
list($featuredRecords, $featuredMetaData) = getRecords(array(
'tableName' => 'artists',
'limit' => '1',
'allowSearch' => '0',
));
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '3',
'offset' => '2',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category NOT LIKE '%features%' AND category LIKE '%news%'",
'allowSearch' => '0',
));
$newsnums = '';
foreach ($newsRecords as $news) {
$newsnums .= $news['num'] . ',';
}
$newsnums = trim($newsnums, ',');
list($featuresRecords, $featuresMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '3',
'offset' => '1',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category LIKE '%features%' AND num NOT IN ($newsnums)",
'allowSearch' => '0',
));
list($sliderfeaturesRecords, $sliderfeaturesMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '1',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category LIKE '%features%' AND num NOT IN ($newsnums)",
'allowSearch' => '0',
));
list($reviewsRecords, $reviewsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '3',
'offset' => '1',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category LIKE '%reviews%' AND num NOT IN ($newsnums)",
'allowSearch' => '0',
));
list($resultsRecords, $resultsMetaData) = getRecords(array(
'tableName' => 'news',
'offset' => '1',
'limit' => '3',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category LIKE '%results%' AND num NOT IN ($newsnums)",
'allowSearch' => '0',
));
list($sliderresultsRecords, $sliderresultsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '1',
'orderBy' => 'publishDate DESC',
'where' => "hidden != 1 AND publishDate < NOW() AND category LIKE '%reviews%' AND num NOT IN ($newsnums)",
'allowSearch' => '0',
));
list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',
'limit' => '3',
'orderBy' => 'createdDate DESC',
'allowSearch' => '0',
));
list($jobRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'jobs',
'limit' => '3',
'orderBy' => 'createdDate DESC',
'allowSearch' => '0',
));
?>
the code for the track list is here:
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF"><div class="siHeaderBlueHome">Latest Soca Releases </div>
<div style="background-color: #C0DEED; height: 1px; width: 100%; margin: 0px 0 0px 0;"></div>
<div class="articleContent">
<?php foreach ($toptracksRecords as $track): ?>
<?php @$artist = getArtist($track['artists']); ?>
<?php foreach ($track['upload'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<?php continue; ?>
<?php else: ?>
<?php if (@$artist[0]['image']): ?>
<img src="<?php echo @$artist[0]['image'][0]['urlPath']; ?>" width="75" border="0" style="float: left; padding-right: 2px;" />
<?php else: ?>
<?php endif; ?>
<a href="./music" class="articleContentBold"><?php echo $track['title'] ?></a>| <?php echo $track['artists'] ?><br/>
<span class="eventIndexMore"><?php echo $track['country'] ?> | <?php echo $track['album_riddim'] ?> | <?php echo $track['year'] ?> | <?php echo $track['plays']; ?> Plays</span><br/>
<div style="background-color: #C0DEED; height: 1px; width: 100%; margin: 10px 0 5px 0;"> </div>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach ?>
</div></td>
</tr>
</table>
Re: [socanews] Playing Track Function
By Chris - November 26, 2010
Hi socanews,
From the code you posted, I can see that your links don't contain any information on which track to play:
You'll need to add some information to your URLs to identify tracks. For example:
From looking at the source of one of the URLs you posted earlier, it seems like you'll need to output some JavaScript to get the selected track playing.
From the code you posted, I can see that your links don't contain any information on which track to play:
<a href="./music" ...
You'll need to add some information to your URLs to identify tracks. For example:
<a href="./music?trackNum=<?php echo $record['num']; ?>" ...
From looking at the source of one of the URLs you posted earlier, it seems like you'll need to output some JavaScript to get the selected track playing.
All the best,
Chris
Chris