title: PHP - Retrieving IPs from host names
body: <p>I am retrieving values from a table field and appending a string to it to get a list of host names.  I would then like to loop through all the host names and return the IP for each.</p>
  
  <p>The following code gets my host names:</p>
  
  <pre><code>$sql = "select * from table order by col1 asc";
  
  $q = mysql_query($sql) or die(mysql_error() ." " . $sql);
  
  // Loop through table and append .zzz to each col1.
  while ($r = mysql_fetch_array($q)) {
  
      $host_name = $r['col1']. ".zzz" . " ";
  
      //echo $host_name;
  }
  </code></pre>
  
  <p>The above code works as it should, but I am unsure how to retrieve the IPs for each host name.  I have been trying gethostbyname but can't get it to work correctly.  I know I have to loop through the host name values.  Would I use a foreach loop?  I have tried that and can't get it working.  Can someone give me some pointers please.</p>
  
  <p>I have tried the following but it doesn't return anything:</p>
  
  <pre><code>$host_name_ip = $host_name;
  foreach ($host_name_ip as $name) {
      $ip = gethostbyname($name);
      echo '&lt;li&gt;' . $ip. '&lt;/li&gt;';
  }
  </code></pre>
  
  <p>I have also tried this... again, nothing:</p>
  
  <pre><code>foreach($host_name as $url) {
      $ip = gethostbyname(trim($url)); 
  }
  
  echo $ip;
  </code></pre>
  
  <p>Thanks. :) </p>