How to Add a Client-Side category based on MySQL results

From a MySQL database results, on the client-side I want to be able to add 1 additional category on the results table based on the database results.

Example: MySQL data “happy”, “glad”, “euphoric” become linked to a the client-side category of “Happiness.” MySQL data “sad”, “sadness”, “gloom” become linked to a the client-side category of “Depression.”

TABLE results example:

Mood State — Mood Category (client-side generated)


Happy - Happiness
Sad - Depression
Euphoric - Happiness
Glad - Happiness
Gloom - Depression

Any idea how I can code it?
I don’t want to mess with the MySQL database such as adding another column to the table.

Hi @jcr
can you explain how should this be working on your page?

Two table columns:

  1. Left column for the MySQL results (e.g., “beer”, “whisky”, “tequila”).
  2. Right column with the client-side generated category for each left column result, in this case “Alcoholic Beverage” category. The “Alcoholic Beverage” category does not exist on the MySQL database, and I want to be able to dynamically create the category on the client-side of the web page for each individual result of the MySQL data.

So do you just want to replace some records with with category1 then some other records with category2 etc. in a repeat region?
For example instead of showing:

record1
record2
record3
record4
record5

You want to show

category1
category1
category1
category2
category2
?

Left table column showing:
record1 (“beer”)
record2 (“whisky”)
record3 (“Pepsi”)
record4 (“tequila”)
record5 (“Coca Cola”)

Right table column showing:
category1 (“Alcoholic Beverages”)
category1 (“Alcoholic Beverages”)
category2 (“Soft Drinks”)
category1 (“Alcoholic Beverages”)
category2 (“Soft Drinks”)

You need to use the Group By Data Formatter for this, so 4 states of Happiness are all grouped as Happiness and 20 states of depression are grouped together as sadness.

Hi @psweb, @jcr says he doesn’t have the categories in the database table.

The best solution would be to add another column with the categories, but if you don’t want to do this just add multiple replace filters to the value:

1 Like

Yup, you are right, Grouping is not going to work without all the data in the database, cant use grouping when some data is from the database and other data is generated Client Side, sorry @jcr I did not think of that.

I duplicated the cell with the data bindings and the “replace” feature worked well. How can I “replace with” the whole database text string based on a partial “search for”?

Example:
Database text: “extremely depressed”

“Search for” depressed
“Replace with” Depression

Text showing on webpage: extremely Depression

I need to be able to remove the whole text string with my “replace with” text.

Also, if my “search for” (e.g., depressed) does not appear on the database records, I need to be able to show a blank field on the webpage instead.

Granted, I may need to just add an extra table to the MySQL database but with 80K+ records and the eventual need to update the database with a clean updated install, I am just dreading all the errors I may cause to the new install, because the records sequence will be different on the new install.