0

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?

3
  • 1
    The '$row' is an array containing all the values returned by your query. So in your loop something like: echo "$row[groupId], $row[groupName]"\n; Commented Mar 23, 2016 at 16:40
  • 1
    As Kurt wrore fix this first: $qid = $mysqli->query($sql); then $row->groupId, $row->groupName, $row->device_id contains values from db Commented Mar 23, 2016 at 18:01
  • 1
    @user3741598 your way works with fetch_assoc function but Skyluk uses fetch_object function Commented Mar 23, 2016 at 18:03

1 Answer 1

1

$qid = $mysqli->query($qry); should be $qid = $mysqli->query($sql);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.