Autimatisch and Ende der Seite scrollen & datesim > vor 5 minuten

Hallo,

wie kann ich der Seite sagen, dass er bis zum ende der Seite Scrollt?

mysql_query("SELECT * FROM `tabelle` WHERE ....");

Wie kann ich hier nur die Zeilen ausgeben, die vor 5 Minuten eingefügt wurden? Beim einfügen wird „NOW()“ ind die spalte eingefügt (datetime).

MFG
Kyroy

wie kann ich der Seite sagen, dass er bis zum ende der Seite Scrollt?

Da hilft eine Websuche nach etwa „html seitenende scrollen“.

Wie kann ich hier nur die Zeilen ausgeben, die vor 5 Minuten eingefügt wurden?

Das hier gibt beispielsweise alle Datensätze aus, die innerhalb der letzten 5 Minuten hinzugefügt wurden:

Edit: Der Befehl passt nicht. Siehe threadi in #4

SELECT spalte1, spalte2 FROM tabelle WHERE MINUTE(TIMEDIFF(NOW(), spalte_datum)) < 5

Danke für diene Hilfe, allerdings gibt es bei deinem code einen kleinen hacken. Er zeigt auch eine Stunde später das an, was vor einer Stunde in den letzten 5 minuten angezeigt wurde.

Sprich:
es ist 10:45 uhr
und er geigt an, was um 9:44uhr passiert ist
edit: und ich denke das gleiche wird mit tagen etc auch sein

DATE_SUB wäre das Richtige für dich. (auch unter MySQL :: MySQL 5.1 Reference Manual :: 11.6 Date and Time Functions dokumentiert).

SELECT spalte1, spalte2 FROM tabelle WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) >= spalte_mit_datetime

Danke für diene Hilfe, allerdings gibt es bei deinem code einen kleinen hacken. Er zeigt auch eine Stunde später das an, was vor einer Stunde in den letzten 5 minuten angezeigt wurde.

Oh, pardon. :slight_smile: Ich editiere mal eine entsprechenden Hinweis in meinen Post rein.

damit klappts…

SELECT spalte1, spalte2 FROM tabelle WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <= spalte_mit_datetime

muss <= sein^^ danke :slight_smile:

Das ist die Tabelle (die 3 zeilen in der mitte sind hier irellevant :wink: )

date name guild x y type message 2010-06-14 20:47:43 Kyroy 0 202 203 global test 2010-06-14 20:47:47 Kyroy 0 202 203 global test1 2010-06-14 20:47:51 Kyroy 0 202 203 global test2 2010-06-14 20:47:54 Kyroy 0 202 203 global test3Ausgabe kurz danach, keine 5 minuten ;):

[SIZE=3][2010-06-14 20:47:47][B]Kyroy[/B](global): test1[/SIZE] [SIZE=3][2010-06-14 20:47:51][B]Kyroy[/B](global): test2[/SIZE] [SIZE=3][2010-06-14 20:47:54][B]Kyroy[/B](global): test3[/SIZE]Hier der php code:

[PHP] $result = mysql_query("
SELECT * FROM chat WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <= date
")or die("Fehler: " . mysql_error());
$count = mysql_num_rows($result);
$row = mysql_fetch_array($result, MYSQL_BOTH);
for($i=0; $i<=$count;$i++){
$row = mysql_fetch_array($result, MYSQL_BOTH);
$date = $row[„date“];
$name = $row[„name“];
$guild = $row[„guild“];
$x = $row[„x“];
$y = $row[„y“];
$type = $row[„type“];
$message = $row[„message“];
if($i == $count)
echo’

‚;
if($type == „global“)
echo‘
[‚.$date.‘]‚.$name.‘(‚.$type.‘): ‚.$message.‘

;
if($type == „lokal“){
if($x == $x_char && $y == $y_char)
echo’
[‚.$date.‘]‚.$name.‘(‚.$type.‘): ‚.$message.‘

;
}
if($i == $count)
echo’
‚;
}
echo‘';
mysql_free_result($result);[/PHP]

Nun ist meine Frage, warum gibt er die erste Zeile nicht aus?

Ich würde dafür eher eine einfacher zu handhabende while()-Schleife verwenden.

Dann schlag ma vor wie. Bei der letzten Zeile miss das DIV id=lastline rein

[code]$arr = range(1, 10);

$end = end($arr);
reset($arr);

while( list($k, $v) = each($arr) )
{
if( $n == $end )
{
echo ‚last!‘;
}
else
{
echo sprintf('%s ', $v);
}
}[/code]

Siehe: How do you find the last element of an array while iterating using a foreach loop in php ? - Stack Overflow

[PHP]$result = mysql_query("
SELECT * FROM chat WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <= date
")or die("Fehler: " . mysql_error());
$end = end($result);
$count = 1;
while($row = mysql_fetch_array($result, MYSQL_BOTH)){[/PHP][B]Warning[/B]: end() [[function.end](http://dominationone.de/magic_war/woodlands/chat/function.end)]: Passed variable is not an array or object in [B]/**/**/**/**/**/chat.php[/B] on line [B]32[/B] [SIZE=3][2010-06-17 00:27:21][B]Kyroy[/B](global): test[/SIZE] [SIZE=3][2010-06-17 00:27:24][B]Kyroy[/B](global): test[/SIZE] [SIZE=3][2010-06-17 00:27:26][B]Kyroy[/B](global): test[/SIZE] line 32 ist die $end = end($result);
habs auch schon so getestet:
$end = end(array_keys($result));

$result ist lediglich die Resultset-Ressource der SQL-Abfrage. Damit der Code von threadi funktioniert, müsstest du erst alle Datensätze abholen und in ein Array schreiben.

[php]function getData()
{
$data = array();

$result = mysql_query("
    SELECT * FROM `chat` WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <=  `date`
    ") or die("Fehler: " . mysql_error());

while ($row = mysql_fetch_assoc($result)) {
    $data[] = $row;
}

mysql_free_result($result);

return $data;

}[/php]

Das macht man oft aus Gründen des Anwendungsdesigns automatisch so. Aber, na ja, ich würde hier für die Ausgabe dann ehrlichgesagt auch count() verwenden.

[php]$data = getData();
$count = count($data);

for ($i = 0; $i < $count; $i++) {
// usw.
}[/php]