Hi all!
I got a finished script which reads out alle the data from a file called arp.dat
My Script:
$fp = fopen('arp.dat', 'r');
$row = array();
while(!feof($fp))
{
$line = fgets($fp,1000);
$data = explode(" ", trim($line));
if($order == 'NAME')
{
$key = $data[3];
}
else if($order == 'IP')
{
$key = $data[1];
}
else if($order == 'MAC')
{
$key = $data[0];
}
else
{
$key = $data[2];
}
$row[$key] = array($data[3], $data[1], $data[0], $data[2]);
}
ksort($row, SORT_REGULAR);
echo '<table>
<tr>
<td><b><a href="index.php?order=IP">IP-Adresse</a></b></td>
<td><b><a href="index.php?order=MAC">MAC-Adresse</a></b></td>
<td><b><a href="index.php?order=NAME">NAME</a></b></td>
<td><b><a href="index.php?order=TIME">TIME</a></b></td>
</tr>';
foreach($row as $data)
{
echo "<tr><td>$data[1]</td>
<td>$data[0]</td>
<td>$data[3]</td>
<td>$data[2]</td></tr>";
}
fclose($fp);
echo '</table>';
actually my script is way more longer, but i think thats the part where everything important happens
My arp.dat-file
0๐
ฑb๐
ฑb:b 192.168.1.3 1087368085 pc2
0๐
ฐa๐
ฐa:a 192.168.1.2 1095850759 pc1
0:c:c:c:c:c 192.168.1.1 1097679853 pc3
0:d:d:d:d:d 192.168.1.2 1096280091 pc4
The script displays this stuff in right order (sorted by IP-adress by starting the script) and so on.
everything just works great but there is one problem:
when there is a line which got the same content then another line (for example: both line got the same
IP-adress, everything else is different), then my script wont display both lines when i am trying to order
by the topic, where they both are the same (in this case: order by IP-adress). It just displays the line
which stands lower in the arp.dat-file. it seems to, that the lower line overwrites the line with same
content. but this happens only, as i said, if i order by the topic, under which the lines with the same
content stands.
Here another example:
arp.dat-file
0๐
ฑb๐
ฑb:b 192.168.1.3 1087368085 pc2
0๐
ฐa๐
ฐa:a 192.168.1.2 1095850759 pc1
0:c:c:c:c:c 192.168.1.1 1097679853 pc3
0:d:d:d:d:d 192.168.1.2 1096280091 pc4
my script will display that in a nice table (not ordered):
table un-ordered
192.168.1.3 0๐
ฑb๐
ฑb:b pc2 1087368085
192.168.1.2 0๐
ฐa๐
ฐa:a pc1 1095850759
192.168.1.1 0:c:c:c:c:c pc3 1097679853
192.168.1.2 0:d:d:d:d:d pc4 1096280091
but if I order by IP adress now, it display the following:
table ordered by IP
192.168.1.1 0:c:c:c:c:c pc3 1097679853
192.168.1.2 0:d:d:d:d:d pc4 1096280091
192.168.1.3 0๐
ฑb๐
ฑb:b pc2 1087368085
... the second line with the nother ip adress 192.168.1.2 just seems to be overwritten.
if i order by name, everything is just fine again (because no name is appearing twice) and my table would
look like this:
table ordered by name
192.168.1.2 0๐
ฐa๐
ฐa:a pc1 1095850759
192.168.1.3 0๐
ฑb๐
ฑb:b pc2 1087368085
192.168.1.1 0:c:c:c:c:c pc3 1097679853
192.168.1.2 0:d:d:d:d:d pc4 1096280091
so whats wrong with my script ? how can i let display line's with same content without getting them overwritten when i order by them?
btw: i am using Apache 1.3.20 (win32) and PHP 4.0.3
if you need any more informations please feel free to ask
Would be really great if you could help me
thanks in advance and sorry for my worse english ๐