I need to compare 2 tables, where one has the data and the other one has the explanation.
So the data table looks like this:
id | state | substate | stage | suppressed
001 wip A1 B3 Y
003 wip A1 B1 N
005 done A2 B3 Y
009 wip A1 B3 N
... and many more similar
The explanation table has to get the 4 states above (state, substate, stage, suppressed) and translates them to human readable:
state | substate | stage | suppressed | HRoutput1 | HRoutput2
wip A1 B1 N "it's ok" "wait...dont do anything"
wip A1 B3 N "it's not ok" "better call saul"
done A2 B3 Y "it's not ok" "forget about it"
wip A1 B1 Y "it's ok" "something minor needs to be done"
* * * Y "it's ok" "it's suppressed"
done * * * "it's ok" "it's being worked on"
Now see the above explanation table has 2 stages where i used wildcards in the table
*,*,*,Y,"it's ok","its suppressed"
This should be used when state, substate, stage and suppressed are not matched in any of the above criteria.
What I did until now is, I loaded each line on the data into an array A
then let the element array A run through the explanation table:
"SELECT * from explanation_table where state = '" . $data['state'] ."' and '" . $data['substate'] . "' ....etc etc
Then ran the query and saved the result into an explanation array and printed the result
$data['id'] . $expl['HRoutput1'] . $expl['HRoutput2']
My code worked fine except for the cases with wildcards.
To resume from your query, you could do:
This way, you’ll match both wildcards and exact state/substate/… matches, valueing the real matches higher than the wildcard matches (the order by) and returning only the best matching result.