news blättern?

vodka

Mitglied
Hallo ich hab ein newssystem gemacht aber ich weis jetzt nicht wie ich nach 5 news das erste das ich geschrieben habe auf eine andere seite kommt also wie hier:

hier

dort steht doch 1 | 2 | 3 | 4 | 5 |... wie mach ich das
 
[Hier mein Script:

$offs und $num kann man ins MySQL Query einbauen "LIMIT $offs, $num"

Mit der Ausgabe:
Seite: << 1 2 3 4 5 >>

Bei mehr als 10 Seiten erscheint ein "..."
Kann man auf jeden Fall noch variieren.

PHP:
$offs = $_GET["offs"];
$num = $_GET["num"];

$actual_page = ($offs / $num) + 1;
// Navigationsleiste << 1 2 .... >>
echo "Seite: ";
if ($actual_page != 1)
{
	$foo = $offs - $num;
	echo "<a href='?num=$num&offs=$foo'>&lt;&lt;</a>&nbsp;";
} else {
	echo "&nbsp;&nbsp;&nbsp;&nbsp;";
}

if (ceil ($all / $num) > 10)
{
	$min = $actual_page - 10;
	if ($min <= 0)
	{
		$min = 0;
	} else {
		echo "<a href='?num=$num&offs=0' class='link'>1</a>&nbsp;...";
	}
	$max = $actual_page + 10;
	if ($max > ceil ($all / $num) )
	{
		$max = ceil ($all / $num);
	}
} else {
	$min = 0;
	$max = ceil ($all / $num);
}
for ($i = $min; $i < $max; $i++)
{
	$foo = $i + 1;
	$offsfoo = $i * $num;
	if ($actual_page != $i + 1)
	{
		echo "<a href='?num=$num&offs=$offsfoo'>$foo</a>&nbsp;";
	} else {
		echo "<u>$foo</u>&nbsp;";
	}
}
if (ceil ($all / $num) > 10 && $actual_page + 10 < ceil ($all / $num) )
{
	$offsfoo = (ceil ($all / $num) - 1) * $num;
	$foo = ceil ($all / $num);
	echo "...<a href='?num=$num&offs=$offsfoo'>$foo</a>&nbsp;";
}
if ($actual_page < ceil ($all / $num) )
{
	$foo = $offs + $num;
	echo "<a href='?num=$num&offs=$foo'>&gt;&gt;</a>&nbsp;";
} else { 
	echo "&nbsp;&nbsp;&nbsp;&nbsp;";
}
// ENDE der Navigationsleiste

Ich hoffe das hilft dir weiter.

Sieht dann aus wie hier
 
Zuletzt bearbeitet:
Also:

Erst einmal solltest du die MySQL Queries so umstellen, dass am Ende "LIMIT $offs, $num" steht. $offs und $num sollten einen Standardwert besitzen. $offs = 0, $num = 5

Wenn $_GET["offs"] und $_GET["num"] gesetzt sind, dann verwendest du diese Werte.

Dann kopierst du das obige, fügst in den <a> Tags das Ziel ein.

Und danach die Anzeige.
 
So mein code:
PHP:
<?php
// Zur config datei Includen //
include "dbnews.php";

// Verbindung mit der Datenbank erstellen //
$db = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");



// Tabelle //

$query = "SELECT *, DATE_FORMAT(datum,'%d.%m.%y') AS datum_de FROM anews ORDER BY id DESC LIMIT $offs, $num";
$result = mysql_query($query);
while($r=mysql_fetch_array($result))
{
$name=$r["name"];
$titel=$r["titel"];
$news=$r["news"];
$email=$r["email"];
$link=$r["link"];
$datum=$r["datum_de"];
$id=$r["id"];

$s1 = "SELECT  * FROM acomments  WHERE newsid = '$id'" ;
$q1 = mysql_query($s1) ;
$comments_anzahl = mysql_num_rows($q1) ;


$offs = $_GET["offs"];
$num = $_GET["num"];

$actual_page = ($offs / $num) + 1;
// Navigationsleiste << 1 2 .... >>
echo "Seite: ";
if ($actual_page != 1)
{
    $foo = $offs - $num;
    echo "<a href='?num=$num&offs=$foo'>&lt;&lt;</a>&nbsp;";
} else {
    echo "&nbsp;&nbsp;&nbsp;&nbsp;";
}

if (ceil ($all / $num) > 10)
{
    $min = $actual_page - 10;
    if ($min <= 0)
    {
        $min = 0;
    } else {
        echo "<a href='?num=$num&offs=0' class='link'>1</a>&nbsp;...";
    }
    $max = $actual_page + 10;
    if ($max > ceil ($all / $num) )
    {
        $max = ceil ($all / $num);
    }
} else {
    $min = 0;
    $max = ceil ($all / $num);
}
for ($i = $min; $i < $max; $i++)
{
    $foo = $i + 1;
    $offsfoo = $i * $num;
    if ($actual_page != $i + 1)
    {
        echo "<a href='?num=$num&offs=$offsfoo'>$foo</a>&nbsp;";
    } else {
        echo "<u>$foo</u>&nbsp;";
    }
}
if (ceil ($all / $num) > 10 && $actual_page + 10 < ceil ($all / $num) )
{
    $offsfoo = (ceil ($all / $num) - 1) * $num;
    $foo = ceil ($all / $num);
    echo "...<a href='?num=$num&offs=$offsfoo'>$foo</a>&nbsp;";
}
if ($actual_page < ceil ($all / $num) )
{
    $foo = $offs + $num;
    echo "<a href='?num=$num&offs=$foo'>&gt;&gt;</a>&nbsp;";
} else { 
    echo "&nbsp;&nbsp;&nbsp;&nbsp;";
}
// ENDE der Navigationsleiste
echo "<table style='BORDER-COLLAPSE: collapse' table width='330' border='1' cellspacing='0' cellpadding='0' bordercolor='#000000'>
<tr>
    <td width='33%'>$titel</td>
    <td width='32%'>
      <div align='center'>$datum<a href='mailto:$email'></a></div>
    </td>
    <td width='35%'>
      <div align='center'>Von: <a href='mailto:$email'>$name</a></div>
    </td>
  </tr>
</table>
<table width='330' border='0' height='24'>
  <tr>
    <td valign='top'>$news</td>
  </tr>
</table>

<table style='BORDER-COLLAPSE: collapse' table width='330' border='1' cellspacing='0' cellpadding='0' bordercolor='#000000'>
  <tr>
    <td width='68%'>Link: <a href='http://www.$link'>$link</a></td>
    <td width='32%'>
      <div align='center'><a href='http://www.dalton-clan.com/clan/admin/news/comments.php?id=$id'>comments</a>($comments_anzahl)</div>
    </td>
  </tr>
</table>
<table width='330' border='0' cellspacing='0' cellpadding='0' bordercolor='#000000'>
  <tr>
    <td width='68%'>&nbsp;</td>
  </tr>
  <tr>
    <td width='68%'>&nbsp;</td>
  </tr>
  <tr>
    <td width='68%'>&nbsp;</td>
  </tr>
</table>";
}


?>
Das geht aber ned in der Zeile
PHP:
$query = "SELECT *, DATE_FORMAT(datum,'%d.%m.%y') AS datum_de FROM anews ORDER BY id DESC LIMIT $offs, $num";
hat es ein fehler aber welchen?
 
Also ich habs nochmal versucht geht aber ned!Es liegt nicht nur an dieser Zeile hab glaubs auch was anderes falsch kann mir jemand sagen was?
 
also, ich habs ma ausprobiert, doch leider zeigt er nur die ersten 15(<< von mir gesetzte maximale) beiträge an. Keine weiteren Links um den Rest zu zeigen.
 
Zurück