title: php host status with ping with results of a mysql query
body: <p>I have a database that I have created that I use to keep up with my list of static IPs on my network. I have a page that lists the ips in order, my script to list the ips and other data from the database works, but I want to add a script to ping each ip address and tell whether it's up or not, here is the code I have to display everything:</p>
  
  <pre><code>$dbConn = connectToDb();
  
  $sql= &lt;&lt;&lt; END
  
  SELECT *
  FROM `ipadds` 
  ORDER BY oct1 ASC, oct2 ASC, oct3 ASC, oct4 ASC;
  
  END;
  
  $result=mysql_query($sql) or die(mysql_error()); 
  
  
  
  $options=""; 
  
  
  
  while ($row=mysql_fetch_array($result)) {
  
      $oct1=$row['oct1']; 
      $oct2=$row['oct2']; 
      $oct3=$row['oct3']; 
      $oct4=$row['oct4']; 
      $SubnetMask=$row['SubnetMask']; 
      $Hostname=$row['Hostname']; 
      $MAC=$row['MAC']; 
      $Description=$row['Description']; 
      $DeviceType=$row['DeviceType']; 
      $Location=$row['Location']; 
      $Comments=$row['Comments']; 
  
      $options.="&lt;tr&gt;&lt;td&gt;&lt;a href=editcomputer.php?queryID=$id&gt;&lt;img src=images/edit.gif alt=print border=0&gt;&lt;/a&gt; &lt;a href=deletecomputer.php?queryID=$id&gt;&lt;img src=images/edit-delete-icon.png alt=print border=0&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href='HTTP://$oct1.$oct2.$oct3.$oct4' target=_blank&gt;$oct1.$oct2.$oct3.$oct4&lt;/a&gt;&lt;/td&gt;&lt;td&gt;$SubnetMask&lt;/td&gt;&lt;td&gt;$Hostname&lt;/td&gt;&lt;td&gt;$MAC&lt;/td&gt;&lt;td&gt;$Description&lt;/td&gt;&lt;td&gt;$DeviceType&lt;/td&gt;&lt;td&gt;$Location&lt;/td&gt;&lt;/tr&gt;";
  
  }
  ?&gt; 
  &lt;center&gt;
  
  &lt;font size=-1&gt;
  
  &lt;img src="images/edit.gif"&gt; - Edit Computer&lt;br&gt;
  
  &lt;img src="images/edit-delete-icon.png"&gt; - Delete Computer&lt;br&gt;
  
  &lt;/font&gt;
  
  &lt;font size="2"&gt;
  
  &lt;table&gt;
  
  &lt;tr&gt;
  
  &lt;td&gt;
  
  &lt;hr&gt;
  
  &lt;/td&gt;
  
  &lt;/tr&gt;
  &lt;table cellpadding="15" border="1"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  
  &lt;/td&gt;
  &lt;td&gt;
  &lt;u&gt;IP Address&lt;/u&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;u&gt;Subnet Mask&lt;/u&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;u&gt;Hostname&lt;/u&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;u&gt;MAC Address&lt;/u&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;u&gt;Description&lt;/u&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;u&gt;Device Type&lt;/u&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;u&gt;Location&lt;/u&gt;
  &lt;/td&gt;
  
  &lt;?=$options?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I want to add another row to my table and have it as a "Status" of Up or Down, any suggestions?</p>
  
  <p>I found this code, it works all by itself and I specify the address, but can't get it to work in my "while" statement:</p>
  
  <pre><code>function pingAddress($ip) {
      $pingresult = exec("ping -n 3 $ip", $outcome, $status);
      if (0 == $status) {
          $status = "alive";
      } else {
          $status = "dead";
      }
      echo "The IP address, $ip, is  ".$status;
  }
  
  pingAddress("ip addres of host here");
  </code></pre>