I use MySQL (in NodeJS). I have a table with unknown data.
I present the data as an HTML table by looping out the items. Then I add a click event to the cells. When that happens I want to load the data from the current cell.
How can I do that?
What I could do (but don't want to)
I could let the user add a custom_identifier
to specify that in this table, use the id as identifier.
/*
From click event. I click on the cell with `column slug` with `id 3`.
cell = {
identifier: 3,
column: slug,
};
*/
const custom_identifier = "id";
const sql = `SELECT ${cell.column} FROM WHERE ${custom_identifier} = ${cell.identifier}`;
Because this approach requires the user to specify the identifier for each table, I don't want to use this approach.
Problem
When making SQL queries and wanting a particular row, we need a WHERE
statement and an identifier to get the correct row. Some tables don't have an id or even a unique identifier at all.
Question
How can I get the data from a row where I don't know an id?
Ideas
- Is there a kind of index I could use that is not bound to a column name?
- I can add more stuff to my data attributes in the HTML if needed, index or something else. I just don't want to put the load on the user.