Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.php Subject: Re: Regarding split text and match from data base Date: Mon, 25 Nov 2013 08:35:05 +0100 Lines: 90 Message-ID: <5292FDA9.6050902@arnowelzel.de> References: <676203c7-7d21-4513-92d5-7a9111c2eaa6@googlegroups.com> <61da9f2c-8c49-419f-ae32-ba97326e6e57@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: individual.net QXAdjYL6UBfOWbDhH2vYjQ/02y/MoxSBhbl4mkP370d1rxI3WV Cancel-Lock: sha1:lxtUOlx9BfwvNRxhthu60GjorkM= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: <61da9f2c-8c49-419f-ae32-ba97326e6e57@googlegroups.com> X-Enigmail-Version: 1.6 Xref: csiph.com comp.lang.php:11977 jalaf28@gmail.com, 2013-11-25 07:35: > its new solution it works > but it skip some computers > > > > $out=shell_exec("arp -a"); Can you post an example of the output of arp -a on your system? Maybe using preg_match_all() as suggested by Jerry would be the easier way. Also keep in mind, that arp -a may output more than one line. Maybe this is the reason, why some computers are skipped - they produce multiple lines of output, so a simple explode() is not enough. > $ex=explode(" ",$out); > > $j=21; > $k=32; I would prefer: $ip_address = $out[21]; $mac_address = $out[32]; This makes the remaining code easier to read. > $ln=mysql_connect("localhost","root",""); > > if(!$ln) > { > die("Could not Connect to The Server"); > } Shorter - as you already did: $ln = @mysql_connect("localhost", "root", "") or die("Could not connect to the server"); Explanation: @ in front of the mysql_connect() suppresses any error output by the PHP runtime. The construction "function() or die()" will call die() if the function does return false, since "or" will try to evaluate the second expression (die()) if the first one (function()) will return false. In production systems you should also keep in mind that using "root" is usually not a good idea. It's better to create a separate user who only has access to the data you need. > mysql_select_db("mysql") or die("Could Not Connect with database"); You see ;-) > $rs=mysql_query("select * from mac_add"); Since you only want to get the data for one specific MAC address anway - assuming your table field is named "mac": $query = "select * from mac_add where mac='" . mysql_real_escape_string($mac_address) . "'"; $rs = mysql_query($query); > echo "
"; Now you only have one fetch and no loop. Using htmlspecialchars() makes sure, that the output will not be invalid HTML - but if you are sure, that you will never have characters like "&", "<", ">" etc. in your data, you don't need to use it. if( $rr = mysql_fetch_array($rs) ) { echo "" . "" . "" . "" . ""; } echo "
IpSystem Name
" . htmlspecialchars($ip_address) . "" . htmlspecialchars($res[0]) . "" . htmlspecialchars($res[1]) . "
"; mysql_close(); -- Arno Welzel http://arnowelzel.de http://de-rec-fahrrad.de