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 #183916 is a reply to message #183911] Mon, 25 November 2013 14:31 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 11/25/2013 1:35 AM, jalaf28(at)gmail(dot)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(at)attglobal(dot)net
==================
[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: Thu Sep 19 22:37:48 GMT 2024

Total time taken to generate the page: 0.05039 seconds