Mailinglisten-Archive |
Michael Girr wrote:
>$strSQL = mysql_query("select * from tbl_test");
>$Anzahl = mysql_numrows($strSQL);
Datenbanken sortieren besser als PHP:
$strSQL = mysql_query("select Text,
Wert1,
Wert2,
Wert1+Wert2 as Wert3
from tbl_test
order by Wert3 desc");
$Anzahl = mysql_numrows($strSQL);
Michael Girr wrote:
> while ($i < $Anzahl)
> {
> $Text[$i] = mysql_result($strSQL, $i, "Text");
> $Wert1[$i] = mysql_result($strSQL, $i, "Wert1");
> $Wert2[$i] = mysql_result($strSQL, $i, "Wert2");
>
> $Wert3[$i] = $Wert1[$i] + $Wert2[$i];
>
> $i++;
> }
Das schreiben die meisten von uns so:
while($a = mysql_fetch_array($strSQL)) {
$Text[$i] = $a["Text"];
$Wert1[$i] = $a["Text"];
$Wert2[$i] = $a["Wert1"];
$Wert3[$i] = $a["Wert1"] + $a["Wert2"]; # $Wert3[$i] = $a["Wert3"];
$i++;
}
> for(reset($Wert3); $index=key($Wert3); next($Wert3))
> {
> print("$Text[$index] : $Wert1[$index] : $Wert2[$index] : $Wert3[$index]
> <BR>\n");
> }
Das ist falsches PHP3. Hast Du Nullen in Deinem Array als Key?
reset($Wert3);
while(list($k, $v) = each($Wert3)) {
print("$Text[$k] : $Wert1[$k] : $Wert2[$k] : $Wert3[$k] : $v<br>\n");
}
Kristian
--
Kristian Köhntopp, NetUSE Kommunikationstechnologie GmbH
Siemenswall, D-24107 Kiel, Germany, +49 431 386 436 00
Using PHP3? See our web development library at
http://phplib.shonline.de/ (GPL)
php::bar PHP Wiki - Listenarchive