php - Transfer IP accounting to single row table -
regarding other question: ip accounting sql database
i need other script writing. have script fetch info except packets in table , put table single rows of information, script must check every single source, destination , bytes table (i not worried packets) , store other table adds total bandwidth upload , download per ip address.
so must store table 1 column named ipaddress, called downloadtransfer, called uploadtransfer, called totaltransfer (which adds both upload , download , last timestamp.
how can that? have tried info 2 tables not sure on how , have check each other nor select each column , add store new table.
<?php include 'config.php'; $conn = mysqli_connect($sqlserver, $sqlusername, $sqlpassword, $sqldatabase); $query = "select * users" , "select * datapackages"; $result = mysqli_query($conn,$query); echo "<table>"; echo "<tr><th>username</th><th>datapackageid</th><th>datapackagename</th> <th>datalimit</th></tr>"; while($row = mysqli_fetch_array($result)) { $username = $row['username']; $datapackageid = $row['datapackage']; $datapackagename = $row['datapackagename']; $datalimit = $row['datalimit']; echo "<tr><td>".$username."</td><td>".$datapackageid."</td> <td>".$datapackagename."</td><td>".$datalimit."</td></tr>"; } echo "</table>"; ?>
code comment question:
<?php include ("config.php"); $conn = mysqli_connect($sqlserver, $sqlusername, $sqlpassword, $sqldatabase); $query = "select src_address, sum(bytes) ipaccounting group src_address"; $result = mysqli_query($conn,$query); echo "<table>"; echo "<tr><th>src_address</th><th>bytes</th></tr>"; while($row = mysqli_fetch_array($result)) { $src_address = $row['src_address']; $bytes = $row['bytes']; echo "<tr><td>".$src_address."</td><td>".$bytes."</td></tr>"; } echo "</table>"; mysqli_close($conn); ?>
i recommend using data have stored in table other questions linked, , select data there. whereas insert query store data other question:
$sql = "insert accounting (src_address, dst_address, bytes, packets) values ('$src', '$dst', '$bytes', '$packets')";
if want total number of bytes transferred source ip address:
$sql = "select src_address, sum(bytes) total_bytes accounting group src_address";
or can destination address changing src_address dst_address.
it's way, because you're storing data. there's no reason duplicate data in format when it's there.
Comments
Post a Comment