Get user list according to node field value
I think you are getting close. When you use ajax in Drupal, you have to return a render array with commands. In your case it looks like you would want ajax_command_replace. 

Two additional steps should get you up and running.

First, built an html string instead of using print_r to try and send content back to the client. 

    $return_html = '&lt;div class="myclass"&gt;';    
    while ($record = $result-&gt;fetchAssoc()) {
              $return_html.='&lt;div class="my_user"&gt;' . $record['name'] . '&lt;/div&gt;';
            }
    $return_html .= '&lt;/div&gt;';


Then create the ajax object and render array to send back to the client

 $commands[] = ajax_command_replace('#my_selector', 'some html here');
 return array(
      '#type' =&gt; 'ajax',
      '#commands' =&gt; $commands,
    );


In this example, you would need to have a div on your page with an id of 'my_selector' that would receive the new html.