close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Insert Record - Remove spaces and replace with dashes and increment it not unique

Thread began 8/21/2014 11:41 am by dlovas275157 | Last modified 8/21/2014 1:32 pm by Jason Byrnes | 1663 views | 7 replies |

dlovas275157

Insert Record - Remove spaces and replace with dashes and increment it not unique

I am working on a permalink solution, and in order to do so I plan to create unique strings based on another database field.

Ex:

DB Field | Value

careerId: 1
careerTitle: Senior Sales Associate
careerPermalink: senior-sales-associate


I would like when I insert the record for the DataAssist insert server behavior to take the same form field and insert it twice, the second time with any spaces removed and replaced by dashes to accomplish the above data.

Im using <?php echo strtolower(((isset($_POST["careerTitle"]))?$_POST["careerTitle"]:"")) ?> to make it all lowercase, but do not know how to replace spaces with dashes or handle the increment.

Is there a way to easily accomplish this with DataAssist / DataBridge?

Sign in to reply to this post

Jason ByrnesWebAssist

use str_replace()

<?php echo strtolower(((isset($_POST["careerTitle"]))?str_replace(" ","-",$_POST["careerTitle"]):"")) ?>

Sign in to reply to this post

dlovas275157

Jason,

Thanks. That worked great.

Now the more complex part - how can I insert a "-1" at the end if there is already an entry for "Senior Sales Associate", or insert a "-2" if there are already 2 entries for "Senior Sales Associate", and so on?

Upon insert, I would need to check the database for matching entries in the careerTitle database field, count them and add increment if needed in the compiled careerPermalink database field.

Or maybe i just need to make sure the "careerPermalink" field is unique and increment it if needed? No sure how to do this.

Appreciate any further help.

Daniel

Sign in to reply to this post

Jason ByrnesWebAssist

create a recordset to count the occurrences:

SELECT count( * ) AS occuraanceCount
FROM products
WHERE ProductName = paramPost

in the variables section create a new variable as:
name: paramPost
type: text
default value: -1
run time value: $_POST["careerTitle"]


than concatenate the recordset value:

<?php echo strtolower(((isset($_POST["careerTitle"]))?str_replace(" ","-",$_POST["careerTitle"]).(($row_recordsetName["occuraanceCount"] > 0)?$row_recordsetName["occuraanceCount"]:""):"")) ?>
Sign in to reply to this post

dlovas275157

Jason,

Again that worked great. Thank you!

I tried to modify it to make the increment "-2" instead of just "2" but cannot seem to get it right. Can you help with this last mod.

senior-sales-associate2
senior-sales-associate-2

<?php echo strtolower(((isset($_POST["careerTitle"]))?str_replace(" ","-",$_POST["careerTitle"]).(($row_rsOccurrencePermalink["occurrenceCount"] > 0)?$row_recordsetName["occurrenceCount"]:""):"")) ?>

Sign in to reply to this post

Jason ByrnesWebAssist

<?php echo strtolower(((isset($_POST["careerTitle"]))?str_replace(" ","-",$_POST["careerTitle"]).(($row_rsOccurrencePermalink["occurrenceCount"] > 0)?"-".$row_recordsetName["occurrenceCount"]:""):"")) ?>

Sign in to reply to this post

dlovas275157

Perfect! Thank you again for the prompt help.

-DL

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...