Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11978

Re: Regarding split text and match from data base

From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: Regarding split text and match from data base
Date 2013-11-25 08:36 +0100
Message-ID <5292FE17.9040809@arnowelzel.de> (permalink)
References <676203c7-7d21-4513-92d5-7a9111c2eaa6@googlegroups.com> <61da9f2c-8c49-419f-ae32-ba97326e6e57@googlegroups.com> <5292FDA9.6050902@arnowelzel.de>

Show all headers | View raw


Arno Welzel, 2013-11-25 08:35:

> jalaf28@gmail.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

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-22 03:28 -0800
  Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-22 09:24 -0500
  Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-22 16:34 +0100
    Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-22 10:54 -0500
      Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-22 17:50 +0100
        Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-22 13:57 -0500
          Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-23 08:52 +0100
            Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-23 07:05 -0500
              Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-24 17:17 +0100
                Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-24 11:23 -0500
  Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-24 20:02 -0800
  Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-24 22:09 -0800
  Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-24 22:35 -0800
    Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-25 08:35 +0100
      Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-25 08:36 +0100
    Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-25 09:31 -0500
  Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-25 21:32 -0800
  Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-25 21:41 -0800
    Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-26 07:20 -0500
      Re: Regarding split text  and match from data base jalaf28@gmail.com - 2013-11-26 21:22 -0800
        Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-27 12:29 +0100
          Re: Regarding split text  and match from data base Arno Welzel <usenet@arnowelzel.de> - 2013-11-27 12:31 +0100
        Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-27 09:57 -0500
          Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-28 12:27 +0000
            Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-28 11:01 -0500
              Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-28 18:51 +0000
                Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-28 19:27 -0500
                Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-29 02:34 +0000
                Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-28 22:47 -0500
                Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-29 05:01 +0000
                Re: Regarding split text  and match from data base Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-29 07:40 -0500
                Re: Regarding split text  and match from data base Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-29 13:58 +0000

csiph-web