Hi all!
I have got a script which displays the content of a file called "arp.dat" in a table. In addition, the user of this script has got the option to order the table by it headlines (IP adress, computer name, mac adress, time) and to search for a special content (e.g. for a special IP adress)
The PHP-script looks like this (shortened):
<form action="index1.php" method="get">
<?php
//
// R E A D I N G OF THE arp.dat CONTENT
//
// opening the file arp.dat
$fp = fopen('arp.dat', 'r');
$row = array();
while(!feof($fp))
{
// reading the content
$line = fgets($fp,1000);
// exploding the content by a "tab"
$data = explode(" ", trim($line));
// look, how the content schould be sorted (by reading the postet variable $order)
if($order == 'NAME')
{
$key[] = $data[3];
}
else if($order == 'IP')
{
$key[] = $data[1];
}
else if($order == 'MAC')
{
$key[] = $data[0];
}
else
{
$key[] = $data[2];
}
$rows[]=$data;
}
array_multisort($key, SORT_REGULAR,$rows);
//
// D I S P L A Y THE DATA
//
// HEAD of the table
echo '<table border="1" cellpadding="1" cellspacing="0" align="center" bordercolor="#800000" bgcolor="#F0F0F0">
<!-- by clicking on the tableheadline the variable $order" will get postet and the table content will get sorted -->
<tr>
<td><input type="text" name="IPse" SIZE="12"><input type="submit" value="Suchen" name=search></td>
<td><input type="text" name="MACse" SIZE="15"><input type="submit" value="Suchen" name=search></td>
<td><input type="text" name="NAMEse" SIZE="10"><input type="submit" value="Suchen" name=search></td>
<td><input type="text" name="TIMEse" SIZE="16"><input type="submit" value="Suchen" name=search>
</tr>
<tr>
<td><b><a href="index1.php?order=IP">IP-Adress</a></b></td>
<td><b><a href="index1.php?order=MAC">MAC-Adress</a></b></td>
<td><b><a href="index1.php?order=NAME">NAME Name</a></b></td>
<td> <b><a href="index1.php?order=TIME">TIME</b></td>
</tr>';
// displaying the data
foreach($rows as $data)
{
if (empty($search))
{
echo "<tr><td>$data[1]</td>
<td>$data[3]</td>
<td>$data[0]</td>
<td>$dara[2]</td></tr>";
}
if (!empty($search))
{
if (in_array($IPse, $data))
{
echo "<tr><td>$data[1]</td>
<td>$data[3]</td>
<td>$data[0]</td>
<td>$dara[2]</td></tr>";
}
if (in_array($MACse, $data))
{
echo "<tr><td>$data[1]</td>
<td>$data[3]</td>
<td>$data[0]</td>
<td>$dara[2]</td></tr>";
}
if (in_array($NAMEse, $data))
{
echo "<tr><td>$data[1]</td>
<td>$data[3]</td>
<td>$data[0]</td>
<td>$dara[2]</td></tr>";
}
if (in_array($TIMEse, $data))
{
echo "<tr><td>$data[1]</td>
<td>$data[3]</td>
<td>$data[0]</td>
<td>$dara[2]</td></tr>";
}
}
}
// closing arp.dat
fclose($fp);
// closing the table
echo '</table>';
?>
The Problem appears, when I search for a special thing, eg. for a special IP adress. When this IP adress is twice in the arp.dat-file, they both will be displayed in my table, just like it should be. But when i klick on the headline "TIME", to sort my results of this "searched IP" by TIME, it will just display the hole content of the arp.dat- file sorted by TIME and NOT only the 2 found results sorted by TIME.
Of course I know where the problem is, but i really dont know how to solve it.
Can you guys please help me ?? :glare:
Would be great ...
thanks in advance, sry for bad english 🙁
Reiners
edit:
If it isnt possible ... how can I arrange/define, that whenever I search for a IP adress the result will automatically ordered by TIME ?