Sort By Day
12 posts by 2 authors in: Forums > CMS Builder
Last Post: December 21, 2010 (RSS)
By Joseph - December 20, 2010
I have a list of radio shows that i would like sorted in the following order:
Sunday
show 1
show 2
Monday
show 1
show 2
My current list of radio shows can be found at - http://www.socanews.com/music/radioIndex.php.
Thanks
Joseph
Re: [socanews] Sort By Day
By Jason - December 20, 2010
Could you attach radioIndex.php so I can see the code you're using?
Thanks
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] Sort By Day
By Joseph - December 20, 2010 - edited: December 20, 2010
Please see attached page.
Re: [socanews] Sort By Day
By Jason - December 20, 2010
What you can do is first organize your shows by day like this:
list($radioshowsRecords, $radioshowsMetaData) = getRecords(array(
'tableName' => 'radioshows',
));
$radioShowsByDay=array('Sunday'=>array(),'Monday'=>array(),'Tuesday'=>array(),'Wednesday'=>array(),'Thursday'=>array(),'Friday'=>array(),'Saturday'=>array());
foreach($radioshowsRecords as $show){
$radioShowsByDay[$show['day']][]=$show;
}
You can then output your shows by day:
<?php foreach ($radioShowsByDay as $day=>$shows): ?>
<?php if($shows):?>
<tr><td><?php echo $day;?></td></tr>
<?php foreach($shows as $record): ?>
<tr>
<td width="130" bgcolor="#FFFFFF"><div align="right">
<?php foreach ($record['image'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" style="padding: 5px 5px 5px 5px" /><br/>
<?php break; ?>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" style="padding: 5px" /><br/>
<?php break; ?>
<?php endif ?>
<?php endforeach ?>
</div></td>
<td width="5" bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"><a href="<?php echo $record['_link']; ?>" class="siHeaderBlueEventsTitle"><?php echo $record['title']; ?></a><br/><span class="articleContentGalleryDate"><?php echo $record['dj'] ?></span><br />
<span class="articleContentGalleryDate"><?php echo $record['day'] ?> | <?php echo $record['time'] ?></span><br />
</td>
<td width="5" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td colspan="4" bgcolor="#C0DEED"><img src="/_images/site/spacer.gif" width="1" height="15" /></td>
</tr>
<?php endforeach ?>
<?php endif ?>
<?php endforeach; ?>
Give this a try and let me know if you run into any problems.
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] Sort By Day
By Joseph - December 20, 2010
One thing i missed out was the second sort order which is by time, so i am thinking i need to create a new field with the file type date/time with the default value being Current Date.
once this is done then sort by Time also, is this correct?
Joseph
Re: [socanews] Sort By Day
By Jason - December 20, 2010
Once you add that field, you can add an "orderBy" to your query. In this example, I'll assume the field is called "show_time", but you can change that to whatever you want:
list($radioshowsRecords, $radioshowsMetaData) = getRecords(array(
'tableName' => 'radioshows',
'orderBy' => "show_time ASC",
));
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] Sort By Day
By Joseph - December 21, 2010
That all works fine, thanks.
What i would now like to do is to be able to populate my Radio Show article page with the DJs info as per this page - http://www.socanews.com/music/radioArticle.php?Bacchanal-Soca-Show-23.
At the moment i have a Section Editor for Radio Shows where i enter details of the show. I also have another Section Editor for DJs where i enter all the details, images etc for the DJs. What i would like to do is populate my Radio Article page with the DJ info from the DJ Section Editor as oppose to entering the info twice, this way I am only required to update the DJ info once.
I have attached the Radio Article Page.
Joseph
Re: [socanews] Sort By Day
By Jason - December 21, 2010 - edited: December 21, 2010
What you can do is create a drop down field in your radio show section where you pull in a list of djs from your dj section. Use the "get options from the database" option. For the value field, choose num. You can choose whatever field you want for the label field. You can then choose a dj for each radio show.
When displaying the information you can do something like this: (In this example, I'm assuming your dj section is called djs and you field in the radio show section is called dj)
list($radioshowsRecords, $radioshowsMetaData) = getRecords(array(
'tableName' => 'radioshows',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$radioshowsRecord = @$radioshowsRecords[0]; // get first record
list($djRecord,$djMetaData)=getRecords(array(
'tableName' => 'djs',
'allowSearch' => false,
'limit' => 1,
'where' => "num='".intval($radioshowsRecord['dj'])."'",
));
$dj=array();
if($djRecord){$dj=$djRecord[0];}
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] Sort By Day
By Joseph - December 21, 2010 - edited: December 21, 2010
I have added the code as suggested to the radio article page but not sure i have used the code correctly.
<?php foreach ($djsRecord['image'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['urlPath']; ?>" width="620" />
<?php if ($upload['info1']): ?>
<table width="620" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr><td height="25"><DIV class="CAPTION"><?php echo $upload['info1']; ?></div></td>
</tr>
</table>
<?php endif; ?>
<?php endif; ?>
<?php break; ?>
<?php endforeach; ?>
Re: [socanews] Sort By Day
By Jason - December 21, 2010
There were a couple of small syntax errors in the code selecting a dj. Try changing it to this:
list($djsRecord,$djsMetaData)=getRecords(array(
'tableName' => 'djs',
'allowSearch' => false,
'limit' => 1,
'where' => "num='".intval($radioshowsRecord['dj'])."'",
));
$dj=array();
if($djRecord){$dj=$djRecord[0];}
Your code outputting an image seems okay. Give this a try and let me know if you run into any trouble.
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/