Ich brauche ein Benutzer beitreten Datapackage mit dem folgenden Codeaus einer anderen Tabelle SQL Joining
SELECT ip_address, SUM(upload_bytes) as upload_bytes, SUM(download_bytes) as
download_bytes
FROM ((SELECT src_address as ip_address, SUM(bytes) AS upload_bytes, 0 as
download_bytes
FROM ipaccounting
WHERE src_address BETWEEN ('192.168.0.1') AND ('192.168.255.254') AND
dst_address NOT BETWEEN ('192.168.0.1') AND ('192.168.255.254') GROUP BY
src_address)
UNION ALL (SELECT dst_address, 0 AS upload_bytes, SUM(bytes) as
download_bytes
FROM ipaccounting WHERE dst_address BETWEEN ('192.168.0.1') AND
('192.168.255.254') AND src_address NOT BETWEEN ('192.168.0.1') AND
('192.168.255.254') GROUP BY dst_address))
a GROUP BY ip_address
My SQL-Datenbank verfügt über 3 Tabellen IP-Accounting: ipaccounting, Anwender und datapackages. Jedes Datenpaket hat eine eindeutige ID, die ID wird in der Datenpaketspalte in der Benutzertabelle angegeben und die IP-Adresse wird in der Benutzertabelle angegeben.
Ich brauche die Benutzer Datapackage Informationen und IP-Adresse an, damit es wird Echo:
IP-Adresse | Bytes hochladen | Bytes herunterladen | Gesamtanzahl der Bytes | Datenpaket-ID | Anwendername
Mein ganzer Code:
<?php
//Include needed files
require ("config.php");
include ("includes/formatbytes.php");
//Connect to database
$conn = mysqli_connect($SQLserver, $SQLusername, $SQLpassword,
$SQLdatabase);
if (!$conn) {
die("Could not connect: " . mysqli_connect_error());
}
//Convert IP Addresses
$IPRangeStart = ip2long($IPRangeStart);
$IPRangeEnd = ip2long($IPRangeEnd);
//Query database
$query = "
SELECT ip_address, SUM(upload_bytes) as upload_bytes,
SUM(download_bytes) as download_bytes
FROM ((SELECT src_address as ip_address, SUM(bytes) AS upload_bytes, 0
as download_bytes
FROM ipaccounting
WHERE src_address BETWEEN INET_NTOA($IPRangeStart) AND
INET_NTOA($IPRangeEnd) AND dst_address NOT BETWEEN INET_NTOA($IPRangeStart)
AND
INET_NTOA($IPRangeEnd) GROUP BY src_address)
UNION ALL (SELECT dst_address, 0 AS upload_bytes, SUM(bytes) as
download_bytes FROM ipaccounting WHERE dst_address BETWEEN
INET_NTOA($IPRangeStart) AND INET_NTOA($IPRangeEnd) AND src_address NOT
BETWEEN
INET_NTOA($IPRangeStart) AND INET_NTOA($IPRangeEnd) GROUP BY dst_address))
a GROUP BY ip_address ORDER BY INET_ATON(ip_address)";
//Execute query
$result = mysqli_query($conn,$query);
//Display IP information
echo "<table>";
echo "<tr><th>IP Address</th><th>Upload</th><th>Download</th><th>Total</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
$ip_address = $row['ip_address'];
$upload_bytes = $row['upload_bytes'];
$download_bytes = $row['download_bytes'];
$total_bytes = ($upload_bytes + $download_bytes);
$total_bytes = formatBytes($total_bytes);
$upload_bytes = formatBytes($upload_bytes);
$download_bytes = formatBytes($download_bytes);
echo "<tr><td>".$ip_address."</td><td>".$upload_bytes."</td>
<td>".$download_bytes."</td><td>".$total_bytes."</td></tr>";
}
echo "</table>";
mysqli_close($conn);
?>
Hat Ihre Abfrage die Aufgabe erfüllt? Wie haben sich die Ergebnisse Ihrer Anfrage von den gewünschten Ergebnissen unterschieden? –
Meine Abfrage erhält nur die Buchhaltungsdaten, ich kann nicht herausfinden, wie man die Benutzer mit ihren Buchhaltungsdaten verbindet, ich muss den Benutzernamen und die Datenpaket-ID aussprechen, ich werde meine Frage mit meinem gesamten Code aktualisieren –
Hat ipaccounting Tabelle eine datapackageid Säule? –