I hope I am explaining this right; as an example, I would like the user_id:id of the matching value: in a returned jSON Array/Object like so…
[{"user_id":"1","value":"92056,92054,92018"},{"user_id":"3","value":"92056"},
{"user_id":"2","value":"Massachusetts, Wyoming, Tennessee"},
{"user_id":"5","value":"California"},
{"user_id":"9","value":"New Mexico, Mississippi, Washington"},
{"user_id":"11","value":"Nevada"},{"user_id":"8","value":"Oklahoma, Louisiana"},
{"user_id":"6","value":"Montana, Oregon"},
{"user_id":"10","value":"Virginia, Illinois"}]
For example, if my source is 92056, I want to get “1”, because my user_id for 92056 is “1”.
If it is New Mexico, I want “9” and so on.
This value can consist of several hundred zip codes, so I would like a way to rapidly search for either these values or like values as this will not ever be duplicated; each user_id will have multiple unique territories or “value”.
In case this comes up, I am pulling the data from the database with PHP and passing into a JavaScript variable like so (in WordPress)…
<?php
global $wpdb;
$fullPHP = $wpdb->get_results("SELECT user_id, value FROM " . "refer_cimy_uef_data;");
?>
var phpreps = JSON.stringify(<?php echo json_encode($fullPHP); ?>);
$("#phpoutput").html(phpreps);
You’re making this too hard on yourself. Convert the ‘value’ property to an array before you send it to the browser client, and just use indexOf on each value array to check if the search query exists. In the following code, the search function at the bottom is very simple. The first part is some client-side conversion code for converting your value properties into proper arrays.