I faced with one problem. I have a code:
<?php
$mysqli = new mysqli('localhost', 'test', 'test123', 'testdb');
$sql = "
SELECT g.id as groupId, g.name as groupName, d.device_id
FROM librenms.devices as d
INNER JOIN librenms.device_groups as g
ON d.hostname LIKE CONCAT('%', mysql.SPLIT_STR(g.pattern, '\"', 2), '%')
WHERE g.pattern LIKE '_devices.hostname%'
ORDER BY g.id
";
$qid = $mysqli->query($qry);
if($qid->num_rows == 0){
die("no results from MySQL\n");
}else{
while($row = $qid->fetch_object()){ // each row
var_dump($row);
}
}
Main thing is that this code find devices in database witch have the same "string" as devicegroups. And thats ok. But how can I print all the groups separately with devices which belongs which that group? Or how I can print even one group with devices which have same string between "".? Can any one can give some suggestions or smthng?