Array optellen met veschillende waarde
Ik heb een vastloper in een bezoekersteller script. Ik heb het tellertje van Bas genomen echter werkt deze op een bijzondere manier.
-----
In de database:
id, ipaddrs, datum
1 , 00.000.00.000,00.000.00.000,00.000.00.000, 11-12-2007 [voorbeeld]
-----
De Ipadressen zijn door komma's gesplitst. Hoe krijg ik hier het totaal?
===HET SCRIPT===
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?
$dedatum = date('m.Y');
$sql = "SELECT ipaddrs,datum FROM statistieken WHERE SUBSTRING(datum, 4, 7) = '" . $dedatum . "' ORDER BY id";
$sql2 = "SELECT ipaddrs FROM statistieken ORDER BY id";
$res = mysql_query($sql);
$res2 = mysql_query($sql2);
while ($row = mysql_fetch_array($res))
{
$row[ipaddrs] = explode(",", $row[ipaddrs]);
$totips = count($row[ipaddrs]);
}
####TOTAAL - dit lukt dus niet -
while ($row2 = mysql_fetch_assoc($res2))
{
$row2[ipaddrs] = explode(",", $row2[ipaddrs]);
$totips2 = count($row2[ipaddrs]);
$arraypush = array_push($array, $totips2);
$array = array($totips2);
$totaal = array_sum($array);
}
?>
$dedatum = date('m.Y');
$sql = "SELECT ipaddrs,datum FROM statistieken WHERE SUBSTRING(datum, 4, 7) = '" . $dedatum . "' ORDER BY id";
$sql2 = "SELECT ipaddrs FROM statistieken ORDER BY id";
$res = mysql_query($sql);
$res2 = mysql_query($sql2);
while ($row = mysql_fetch_array($res))
{
$row[ipaddrs] = explode(",", $row[ipaddrs]);
$totips = count($row[ipaddrs]);
}
####TOTAAL - dit lukt dus niet -
while ($row2 = mysql_fetch_assoc($res2))
{
$row2[ipaddrs] = explode(",", $row2[ipaddrs]);
$totips2 = count($row2[ipaddrs]);
$arraypush = array_push($array, $totips2);
$array = array($totips2);
$totaal = array_sum($array);
}
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?
$dedatum = date('m.Y');
$sql = "SELECT ipaddrs,datum FROM statistieken WHERE SUBSTRING(datum, 4, 7) = '" . $dedatum . "' ORDER BY id";
$sql2 = "SELECT ipaddrs FROM statistieken ORDER BY id";
$res = mysql_query($sql);
$res2 = mysql_query($sql2);
$array = array($totips2);
while ($row = mysql_fetch_array($res))
{
$row[ipaddrs] = explode(",", $row[ipaddrs]);
$totips = count($row[ipaddrs]);
}
while ($row2 = mysql_fetch_array($res2))
{
$row2[ipaddrs] = explode(",", $row2[ipaddrs]);
$totips2 = count($row2[ipaddrs]);
$arraypush = array_push($array, $totips2);
}
$totaal = array_sum($array);
?>
$dedatum = date('m.Y');
$sql = "SELECT ipaddrs,datum FROM statistieken WHERE SUBSTRING(datum, 4, 7) = '" . $dedatum . "' ORDER BY id";
$sql2 = "SELECT ipaddrs FROM statistieken ORDER BY id";
$res = mysql_query($sql);
$res2 = mysql_query($sql2);
$array = array($totips2);
while ($row = mysql_fetch_array($res))
{
$row[ipaddrs] = explode(",", $row[ipaddrs]);
$totips = count($row[ipaddrs]);
}
while ($row2 = mysql_fetch_array($res2))
{
$row2[ipaddrs] = explode(",", $row2[ipaddrs]);
$totips2 = count($row2[ipaddrs]);
$arraypush = array_push($array, $totips2);
}
$totaal = array_sum($array);
?>
De eerste while levert $totips op met daarin een getal dat het aantal ipnummers aangeeft van het laatst gevonden record uit de eerste query.
De tweede while is al net zo vaag.
Ask Bas :D. 't werkt wel