Tricky Formating

7 posts by 2 authors in: Forums > CMS Builder
Last Post: April 27, 2010   (RSS)

By theclicklab - April 23, 2010

Hi there,

I have a list of destinations which show up in my list viewers like this:

Destinations: <?php echo join(', ', getListLabels('yachts', 'destinations', $record['destinations'])); ?>

Which outputs text like:

Destinations: Australia, Tahiti, New Zealand

How would I go about dropping in a link on each destination seeing as this is being stored in the table like this:

" 1 11 10 "

Many thanks
Jan

Re: [aquaman] Tricky Formating

By Jason - April 26, 2010

Hi,

So you would like to display "Australia", "Tahiti", and "New Zealand" as links? What page would you want it to link to?

We can do this, but it would require some extra coding. If you could attach the file that you're working with, along with the page you would like the link to go to, I can take a look at it for you.

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] Tricky Formating

By theclicklab - April 26, 2010

Hi Jason,

Here is a page we want to link from:

http://luxurychartergroup.dreamhosters.com/yacht-type.php/sailing-1/
See attached file: yacht-type.php

links to:

http://luxurychartergroup.dreamhosters.com/destination.php/tahiti-11/
See attached file: destination.php

Thanks for the help...
Jan

Re: [aquaman] Tricky Formating

By Jason - April 26, 2010

Hi,

Just before where you print out your destinations, put this code:
<?php
$values = getListValues('yachts','destinations',$record['destinations']);
$labels = getListLabels('yachts','destinations',$record['destinations']);
$valuesToLabels = array_combine($values, $labels);
?>


Then, print out your destinations with this code:
<?php foreach ($valuesToLabels as $value => $label): ?>
<a href="destination.php/<?php echo $label."-".$value ?>"><?php echo htmlspecialchars($label); ?></a>,
<?php endforeach ?><br/>


Give this a try and let me know if you run into any issues.
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] Tricky Formating

By theclicklab - April 26, 2010

Hi Jason, that worked great.

One last question, How do I go about removing the comma from the last item?

e.g. currently displays as:

Destinations: Australia, Tahiti,

would like to show it as:

Destinations: Australia, Tahiti

Re: [aquaman] Tricky Formating

By Jason - April 27, 2010

Hi,

You can try replacing where you are displaying your destinations with this:
<?php $count=0; ?>
<?php foreach ($valuesToLabels as $value => $label): ?>
<?php echo ($count==0)? "" : "," ?>
<a href="destination.php/<?php echo $label."-".$value ?>"><?php echo htmlspecialchars($label); ?></a>
<?php $count++;?>
<?php endforeach ?><br/>


Give that a try and let me know if that works for you.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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