0

So I've been trying to check each message from a sql table. My sql table structure is down below:

Example:

|         id         | |   triggervalue     | | triggermessage |
| 633666515413237791 | | hello, world, test | | Trigger works! |

(array like string is something like: hello, world, test)

I want to check each message from each triggervalue column to see if message contains a string from array like string.

Here is what I've done:

I tried to merge every single array like string then send(triggermessage) where the same row of the found array contains, then checking for word.

    connection.query(`SELECT * FROM triggervalue`, (err, rows) => {
        let array = []
        for(i = 0; i < rows.length; i++) {
            let received = rows[i].jsonstring;
            var intarray = received.replace(/^\[|\]$/g, "").split(", ");
            array.concat(intarray)
            // continue code here...
        }
    })

However, I can't get the triggermessage of the same row of found array. How would I go for it? I've been stuck here for quite a while... Sorry if this way of asking is wrong, thanks!

(Sorry if my english is bad)

Altqir
  • 1
  • 2
  • 1
    Hi, its really not clear from your question or your data representation what yo are asking here, can you edit the question and have another try – RiggsFolly Mar 14 '21 at 12:41
  • @RiggsFolly Thanks for replying! I edited the message now, is this what you mean? – Altqir Mar 14 '21 at 12:43
  • 2
    I think you are now seeing why storeing comma delimited lists in a database column is a bad idea. It makes using that data very complicated! Better to redesign your database – RiggsFolly Mar 14 '21 at 12:48
  • https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad – RiggsFolly Mar 14 '21 at 12:49
  • @RiggsFolly Sorry to ping you again... Thanks for replying! But I don't really think of any idea redesigning... Because the number of values inside "array" is undefined, I'm not sure how to redesign it, and also I have to search it via user id, which make it more complicated. Oh, didn't see your above message, sorry... – Altqir Mar 14 '21 at 12:56
  • There are 100's of tutorials and beginners guides out there on the net – RiggsFolly Mar 14 '21 at 12:59
  • "My sql table structure is down below" Do I really miss the table structure? or should I be able to deduct it from some table view, which does not show the _COMPLETE_ table structure. Also things like "is something like:" are very vague.... – Luuk Mar 14 '21 at 13:18

0 Answers0