I have been digging around trying to figure this out for a few days now. The issue is that I have a form that enters data into a MySQL database table and links that data to a service ID. The table contains 3 colums: id
serviceid
and data
. I also have an array (working with a json API) that outputs all items (not linked to a service id) under data
. What I am trying to do is match the service ID with the data, and then only display that specific data from the array.
In a nutshell, if I am viewing service #186, it has the 2 sets of data that I want to be able to pull from the array (not the db). It should only pull the array items ([0]
and [2]
) that match the table column data
with the array item ["name"]
.
+------------+-----------+
| id| serviceid | data
+------------+-----------+
| 3 | 186 | SomeMore |
| 2 | 185 | NotEnough |
| 1 | 186 | Data5 |
+------------+-----------+
array {
["data_bits"]=>
array(5) {
[0]=>
array(3) {
["name"]=> "Data5"
["info"]=> "some info"
["comment"]=> "cool beans"
}
[1]=>
array(3) {
["name"]=> "NotEnough"
["info"]=> "some cool info"
["comment"]=> "warm beans"
}
[2]=>
array(3) {
["name"]=> "SomeMore"
["info"]=> "some bad info"
["comment"]=> "hot beans"
}
}
Currently, I have the SQL query that will select the items that have the service ID.
$get = $pdo->prepare("SELECT data FROM table WHERE serviceid=:serviceid");
$get->bindParam(':serviceid', $serviceid, PDO::PARAM_STR);
$get->execute();
$data_array = array();
while ($db_data = $get->fetch()) {
$data_array[] = $db_data[0];
}
If I echo $data_array[0];
in foreach
statement, it show all data related to the current service.
Sorry if this doesn't make a lot of sense. It's rattling me insane. If you need a better explanation, i'll do what I can to try to clarify.