FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Regarding split text and match from data base
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Regarding split text and match from data base [message #183914 is a reply to message #183913] Mon, 25 November 2013 07:36 Go to previous messageGo to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma:
Senior Member
Arno Welzel, 2013-11-25 08:35:

> jalaf28(at)gmail(dot)com, 2013-11-25 07:35:
>
>> its new solution it works
>> but it skip some computers
>>
>>
>> <?php
>>
>> $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 "<center><table border=1><tr><th>Ip</th><th>System Name</th></tr>";
>
> 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) )

Ooops - this should be:
if( $res = mysql_fetch_array($rs) )

> {
> echo "<tr>" .
> "<td>" . htmlspecialchars($ip_address) . "</td>" .
> "<td>" . htmlspecialchars($res[0]) . "</td>" .
> "<td>" . htmlspecialchars($res[1]) . "</td>" .
> "</tr>";
> }
> echo "</table>";
> mysql_close();



--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: creating key / hash
Next Topic: from mysql in associative array
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 05:40:22 GMT 2024

Total time taken to generate the page: 0.04126 seconds