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 #183938 is a reply to message #183937] Wed, 27 November 2013 11:31 Go to previous messageGo to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma:
Senior Member
Am 27.11.2013 12:29, schrieb Arno Welzel:

> Am 27.11.2013 06:22, schrieb jalaf28(at)gmail(dot)com:
>
[...]
>> $j +=21;
>> $k +=21;
>>
>> }
>
> This makes no sense - you first select ALL records which you then don't
> use at all.
>
> You also assume that every 21th character a new output line of arp

Of course "element", not "character"...

> begins - an very insecure assumption and even more worse you loop
> through the number of records in your mac_add table - so you assume
> there are never more output lines in arp -a than records in your
> database. Therefore if arp will output 15 lines and your table only has
> 10 records you would always miss 5 lines - since the loop only handles
> the 10 records.
>
> If you want to make sure you get a result for every output line from
> "arp -a" you should split the lines of the output and loop through that
> and not the database records.
>
> This is just a quick & dirty hack and may contain typos - but you may
> get the idea:
>
> <?php
> $ln=@mysql_connect("localhost","root","");
>
> if(!$ln)
> {
> // TODO: Gracefully error handling - and not just
> // terminating the script
> die("Could not Connect to the database");
> }
>
> echo "<table>";
>
> // Execute "arp -a" with the output lines in the $output array
> // and the return code of the arp command in $returncode
> exec("arp -a", $output, $returncode);
>
> // TODO: Check $returncode and handle errors
>
> // Loop through all output lines from the arp command
> foreach($output as $line)
> {
> // TODO: Check, if $line contains an IP/Mac address at all
> $elements = explode(" ", $line);
>
> // Build query to look up the entry for a given MAC address
> $query = "select * from mac_add where mac_id='".
> mysql_real_escape_string($elements[32])."'";
>
> // Execute query
> $recordset = mysql_query($query);
>
> // Fetch result and output it if there is one
> if($record = mysql_fetch_array($recordset))
> {
> echo "<tr>" .
> "<td>" . htmlspecialchars($elements[21]) . "</td>" .
> "<td>" . htmlspecialchars($record[0]) . "</td>" .
> "<td>" . htmlspecialchars($record[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: Sat Nov 30 09:52:32 GMT 2024

Total time taken to generate the page: 0.04115 seconds