Reversing Concatenation?

8 posts by 3 authors in: Forums > CMS Builder
Last Post: November 6, 2014   (RSS)

Hi All,

The data in a field in my Accounts table called  "links_sent_dates_and_emails", has the current date and time inserted at the beginning of each entry, followed by a series of submitted email addresses,  and an asterisk appended to the end of the series using this code:

$sent_dates_and_emails =  date("m-j-y g:i:s a").': '.$custom2 .' * '  ;
// $custom2 is a string of email addresses separated by commas

Each time a new series of email addresses is submitted, it is added to the links_sent_dates_and_emails field with this code:

$query = "UPDATE `{$TABLE_PREFIX}accounts` SET
links_sent_dates_and_emails = CONCAT(links_sent_dates_and_emails, '$sent_dates_and_emails'),
updatedByUserNum = '".mysql_escape( $CURRENT_USER['num'] )."',
updatedDate      = NOW()
WHERE num = '".mysql_escape( $CURRENT_USER['num'] )."'";
mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n");

I’m reporting the contents of the field  in a viewer separated by line breaks with this code:

<?php $dates_and_emails =  mysql_escape($CURRENT_USER['links_sent_dates_and_emails']) ; ?>
                    <?PHP $dates_and_emails = preg_replace("[\*]i", "<br /><br />", $dates_and_emails ); ?>
                    <?php echo $dates_and_emails ?>

Any thoughts on how would I change the concatenation code so that the lines of dated email address series ended up with the latest at the top?

Right now the latest is at the bottom since it's always added to the end of the existing data.

Thanks,
Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Damon - October 27, 2014

Hi Jerry,

What about putting the dates and emails into an array and then using the array_reverse function?

http://php.net/manual/en/function.array-reverse.php

Cheers,
Damon Edis - interactivetools.com

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

Thanks for looking at this, Damon,

Sounds like a good idea, but I'm not sure how to put the groups into an array.

All sets start with a date, have a number of emails separated by commas, and end with an asterisk (or another character if that works better).

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Damon - October 28, 2014

Can you give me an example of the date, emails output?

And also how you are going to use them?

The reason I ask is that I'm wondering if the date, email string can be put into an array as a single variable or as separate variables?

Cheers,
Damon Edis - interactivetools.com

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

Hi Damon,

An example of the final date, email output in the 'links_sent_dates_and_emails' field in the accounts table record is:

After the first order:

10-27-14 7:40:34 am: jerry@thecmsbcookbook.com, cookbook@thecmsbcookbook.com, jerry@jkwebdesigns.com *

After the second order (notice that the newest entry is last):

10-27-14 7:40:34 am: jerry@thecmsbcookbook.com, cookbook@thecmsbcookbook.com, jerry@jkwebdesigns.com * 10-27-14 8:07:35 am: jerry@thecmsbcookbook.com, cookbook@thecmsbcookbook.com, jerry@jkwebdesigns.com *

______________________________

An example of the final date, email output in the report viewer is:

After the first order:

10-27-14 7:40:34 am: jerry@thecmsbcookbook.com, cookbook@thecmsbcookbook.com, jerry@jkwebdesigns.com

After the second order (notice that the newest entry is at the bottom):

10-27-14 7:40:34 am: jerry@thecmsbcookbook.com, cookbook@thecmsbcookbook.com, jerry@jkwebdesigns.com

10-27-14 8:07:35 am: jerry@thecmsbcookbook.com, cookbook@thecmsbcookbook.com, jerry@jkwebdesigns.com

______________________________

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Dave - November 5, 2014

Hi Jerry, 

What about swapping this:  CONCAT(links_sent_dates_and_emails, '$sent_dates_and_emails'),

With this:  CONCAT('$sent_dates_and_emails', links_sent_dates_and_emails),

Would that work for you? 

Dave Edis - Senior Developer
interactivetools.com

Thanks Dave,

I'll give it a try in the morning.

It would be nice if turned out that it was that easy...

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php