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


Groups > comp.lang.php > #11980

Re: Regarding split text and match from data base

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Regarding split text and match from data base
Date 2013-11-25 09:31 -0500
Organization A noiseless patient Spider
Message-ID <l6vmvu$2sp$1@dont-email.me> (permalink)
References <676203c7-7d21-4513-92d5-7a9111c2eaa6@googlegroups.com> <61da9f2c-8c49-419f-ae32-ba97326e6e57@googlegroups.com>

Show all headers | View raw


On 11/25/2013 1:35 AM, jalaf28@gmail.com wrote:
> its new solution it works
> but it skip some computers
>
>
> <?php
>
> $out=shell_exec("arp -a");
>
>
>
> $ex=explode(" ",$out);
>
> $j=21;
> $k=32;
>
> $ln=mysql_connect("localhost","root","");
>
> if(!$ln)
> {
> 	die("Could not Connect to The Server");
> }

It's almost never right to use die() like this in a script.  It 
terminates all processing of the page immediately, causing invalid HTML 
to be generated.  Better is to put out a message and not process any 
code which relies on the connection, but allows the rest of the code and 
HTML to complete normally.

> mysql_select_db("mysql") or die("Could Not Connect with database");
>
> $rs=mysql_query("select * from mac_add");

What is the purpose of this statement?  Why do you want to fetch the 
entire table?

> echo "<center><table border=1><tr><th>Ip</th><th>System Name</th></tr>";
> while($rr=mysql_fetch_array($rs))

I'm not sure why you want to go through the entire database here.

> {
> 	$rsr=mysql_query("select * from mac_add where mac_id= '$ex[$k]'");

"select *" is also generally not a good idea.  It is better to specify 
the exact columns you want.  That way if you change the database later, 
it will cause fewer problems.  For instance, if you add a large BLOB 
column, you won't be retrieving a lot of data you aren't using.  Also, 
if you DROP a column or change the columns name, the error will show up 
on the SELECT statement and not later.

> 	while( $res=mysql_fetch_array($rsr))

I prefer mysql_fetch_assoc().  It is clearer because you identify the 
columns by name and not by index, helping to self-document the code.

> 	{
> /*	if($rr[0] == $ex[$k])
> 	{
> 		//echo  $ex[$j] . "    " . $rr[0] . "<br />";
> */
> echo "<tr><td>" .$ex[$j] . "</td><td>" . $res[0] . "</td> </td><td>" .$res[1] . "</td></tr>" ;
> 	}
> 	$j +=21;
> 	$k +=21;
> 	
> 	
> }
>
>
> echo "</table></center>";
>
> mysql_close();
> ?>
>

A couple of other things.  First of all, the mysql_xxx functions are 
deprecated and will eventually disappear.  You should use the newer 
mysqli_xxx() functions.  Most are similar to the mysql_xxx() functions, 
but mysqli_xxx() also provides additional options.

Also, you can get all of the MAC addresses in your arp table at once 
with one query, i.e.

SELECT x,y.z
FROM table
WHERE value in ('val1', 'val2', val3');

It will take a bit of work to build the list of mac addresses, so it's 
probably something you should wait for later.  But it will be much more 
efficient, as you'll only make one call to the database and allow it to 
do the searching for you.

But the main question here is - what is the output of your arp -a command?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

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