Numbered List

10 posts by 3 authors in: Forums > CMS Builder
Last Post: January 19, 2011   (RSS)

By Joseph - January 15, 2011

HI Guys

I have created a chart on the following page http://www.socanews.com/music/charts/charts.php# . What i would like to know how to do is

1. add a numbers list - eg 1, 2, 3...
2. This may be a little more complex, my chart is weekly so i only wish to list the songs that have been played the most over the past 7 days starting 12midnight on a Sunday every week. so that from 12.01am monday morning there is a brand new chart.

current code
<?php foreach ($toptracksRecords as $track): ?>
<?php @$artist = getArtist($track['artists']); ?>

<?php foreach ($track['upload'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<?php else: ?>
<?php if (@$artist[0]['image']): ?>
<img src="<?php echo @$artist[0]['image'][0]['urlPath']; ?>" alt="<?php echo $track['artists'] ?>" width="150" border="0" style="padding: 10px 10px 10px 10px; float:left" />
<?php else: ?>
<div style="float: left; width: 50px; height: 20px; padding-right: 2px;">&nbsp;</div>
<?php endif; ?>

<a href="#" onClick="ajaxPlayCount('<?php echo $track['num']; ?>'); parent.document.player.sendEvent('LOAD', {file:'<?php echo $upload['urlPath']; ?>', type:'sound'}); parent.document.player.sendEvent('PLAY',true);changeIt('' ,'<?php echo $track['artists']; ?>','<?php echo $track['title']; ?>','<?php echo $track['year']; ?>','<?php echo $track['country']; ?>','','<?php echo $track['producer']; ?>');" class="siHeaderBlueEventsTitle"> <?php echo $track['title'] ?></a><br/>

<?php endif ?>
<span class="articleContentHome"><?php echo $track['artists'] ?><?php if ($track['artists2']): ?>|<?php echo $track['artists2'] ?> <?php endif ?></span><br/>

<?php if ($track['country']): ?><span class="articleContentGallery"><?php echo $track['country'] ?> |<?php endif ?>
<?php if ($track['album_riddim']): ?><?php echo $track['album_riddim'] ?> | <?php endif ?>
<?php if ($track['year']): ?><?php echo $track['year'] ?> |<?php endif ?>&nbsp;<?php echo $track['plays']; ?>&nbsp;Plays</span><br/>
<div style="background-color: #C0DEED; height: 1px; width: 100%; margin: 5px 0 5px 0;"></div>
<?php endforeach ?>
<?php endforeach ?>

Re: [socanews] Numbered List

By Jason - January 17, 2011

Hi,

For your first question, you could increment a counter while looping through your records like this: (changes in red)

<?php $count = 0;?>
<?php foreach ($toptracksRecords as $track): ?>
<?php @$artist = getArtist($track['artists']); ?>

<?php foreach ($track['upload'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<?php else: ?>
<?php if (@$artist[0]['image']): ?>
<img src="<?php echo @$artist[0]['image'][0]['urlPath']; ?>" alt="<?php echo $track['artists'] ?>" width="150" border="0" style="padding: 10px 10px 10px 10px; float:left" />
<?php else: ?>
<div style="float: left; width: 50px; height: 20px; padding-right: 2px;">&nbsp;</div>
<?php endif; ?>

<a href="#" onClick="ajaxPlayCount('<?php echo $track['num']; ?>'); parent.document.player.sendEvent('LOAD', {file:'<?php echo $upload['urlPath']; ?>', type:'sound'}); parent.document.player.sendEvent('PLAY',true);changeIt('' ,'<?php echo $track['artists']; ?>','<?php echo $track['title']; ?>','<?php echo $track['year']; ?>','<?php echo $track['country']; ?>','','<?php echo $track['producer']; ?>');" class="siHeaderBlueEventsTitle"> <?php echo $track['title'] ?></a><br/>

<?php endif ?>
<span class="articleContentHome"><?php echo ++$count.". ";?><?php echo $track['artists'] ?><?php if ($track['artists2']): ?>|<?php echo $track['artists2'] ?> <?php endif ?></span><br/>

<?php if ($track['country']): ?><span class="articleContentGallery"><?php echo $track['country'] ?> |<?php endif ?>
<?php if ($track['album_riddim']): ?><?php echo $track['album_riddim'] ?> | <?php endif ?>
<?php if ($track['year']): ?><?php echo $track['year'] ?> |<?php endif ?>&nbsp;<?php echo $track['plays']; ?>&nbsp;Plays</span><br/>
<div style="background-color: #C0DEED; height: 1px; width: 100%; margin: 5px 0 5px 0;"></div>
<?php endforeach ?>
<?php endforeach ?>


As for your second issue, I'm not sure I understand what you're trying to achieve. How are you storing your top tracks currently? Are you looking for a way to show the most played tracks from the previous week? When a track is played, do you store the date/time it was played?

Let me know and we'll see if we can put a solution together. Note, this may be more complicated than what we can handle in the forum and may have to go through our consulting.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Numbered List

By Joseph - January 17, 2011

Hi Jason
Thanks for that the numbering works fine.
i will hold on the second issue for the moment and move to something else.
this page should show a list of the 20 most played tracks on my website but if you look down the list you will see some tracks have only been played 6 times but yet still appear. - http://www.socanews.com/music/charts/charts.php

I think what i was trying to achieve on my second issue was to present my readers with a top 20 list of the tracks played the most over a seven day period. But the list woud change once in that 7 day period.

Re: [socanews] Numbered List

By Chris - January 17, 2011

Hi socanews,

I think what you want to do is order your results by your `plays` field. In your getRecords code, add this line:

list($records, $details) = getRecords(array(
'tableName' => 'listings',
'orderBy' => 'plays DESC',
));


If you want to know how many times each track has been played over a seven day period, you'll need to reset your `plays` field to 0 every seven days. Alternately, you could use a second field for that (e.g. `weekly_plays`,) which you'd need to increment along with your `plays` field when a track gets played.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Numbered List

By Joseph - January 17, 2011

ok, the code you gave me worked.

i will have to go with the second option for calculating how many times a track is played over a 7 day period, but would i need to reset the weekly figures?

Re: [socanews] Numbered List

By Chris - January 18, 2011

Hi socanews,

Yes, you'd need to reset those every week so they start counting from zero again.
All the best,
Chris

Re: [chris] Numbered List

By Joseph - January 18, 2011

Ok, unfortunately that wouldn't be practical.
Is there anyway of updating the page once per week so only once a week would the page be refreshed.

Joseph

Re: [socanews] Numbered List

By Jason - January 19, 2011

Hi Joseph,

The best way to do this would be to have a cronjob running on your server. You can set it to run only once a week, at a certain day and time. You can put the code that resets your values in that script. Once it's running you wouldn't have to worry about it anymore.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Numbered List

By Joseph - January 19, 2011

ok, is the cronjob easy to set up, or will i need the professionals?