Jump to content

Page navigation from while loop


GamerGun

Recommended Posts

Dear,

 

How can i turn this while loop into page navigation? So say that after 10 posts, page 2 is being created which shows posts 20 to 30 (and so on).

 

<?php

    $result = mysql_query("SELECT * FROM berichten ORDER BY id DESC")
    or die(mysql_error());

    include("includes/rating_functions.php");

    $numofrows = @mysql_num_rows($result);
    for($i = 0; $i < $numofrows; $i++)
    {
    $row = mysql_fetch_array( $result );

    $id = $row['id'];
    $message = $row['bericht'];
    $onderwerp = $row['onderwerp'];
    $titel = $row['titel'];

$titel2 = eregi_replace(' ', '-', $titel);
$titel2 = strtolower($titel2);

	$onderwerp2 = strtolower($onderwerp);

$opvragen = "SELECT COUNT(*) AS aantal FROM antwoorden WHERE postid = $id";
$aantal2 = (mysql_query($opvragen));
$getal = mysql_result($aantal2, 'aantal');

           if($i % 2)
                   {
                   $color = "brown";
           $hexcolor = "#e8d6b6";
                   }
           else
                   {
                   $color = "gray";
           $hexcolor = "#f4f4f4";
                   }
       echo "<table border=\"0\" bordercolor=\"#FF0000\" cellpadding=\"0\" cellspacing=\"0\" width=\"578\">";
       echo "<tr class=\"contentbox_top_".$color."\">";
       echo "<td height=\"54\"><b><a href=\"../".$titel2."-".$id.".html\">$titel</a></b> door Anoniem".$id." in <a href=\"../zoeken-".$onderwerp2.".html\">".$onderwerp."</a> op ".$row['datum']."</td>";
       echo "</tr>";
       echo "<tr BGCOLOR=\"".$hexcolor."\">";
       echo "<td>";
echo $message;
       echo "<br><br>";
       echo "<a href=\"javascript:popup('$id')\">Vertel een vriend(in) hierover</a> - ";
       echo "<a href=\"../".$titel2."-".$id.".html\">Geef commentaar ($getal)</a><br><br>";
       echo pullRating($id,true,true,true,NULL);
       echo "</td>";
       echo "</tr>";
       echo "<tr class=\"contentbox_bottom_".$color."\">";
       echo "<td height=\"17\"></td>";
       echo "</tr>";
       echo "</table>";

    }

    echo "<script type=\"text/javascript\">";
    echo "function popup(id){";
    echo "window.open('tell_a_friend.php?nummer=' + id +'','tellafriend_script','scrollbars=1,statusbar=1,resizable=1,width=400,height=510');}";
    echo "</script>";


    ?>

 

Thanks in advance.

 

Pz -T

 

 

Link to comment
Share on other sites

You need to add a "LIMIT" clause to your original query. For instance,

 

$result = mysql_query("SELECT * FROM berichten ORDER BY id DESC LIMIT 10, 10")

 

Will skip over the first 10 results, so the first result you get will be the 11th, and the last the 20th.

 

You will want to develop this further using a constant for the number of items per page and querying some kind of variable, most likely in the $_GET array, for how many items to skip over:

 

// number of items to show on each page
define('ITEMS_PER_PAGE', 10);

// now we're getting the number to start fetching from. This line of code is saying,
// if $_GET['start'] is set and it is numeric, then use it, otherwise default to zero
$start = (isset($_GET['start']) && is_numeric($_GET['start'])) ? $_GET['start'] : 0;

// now do the query: notice now that I'm actually fetching one more than the
// ITEMS_PER_PAGE constant: this will allow us to know whether or not to show
// another "next 10 items" link
$result = mysql_query("SELECT * FROM berichten ORDER BY id DESC LIMIT $start, " . ITEMS_PER_PAGE + 1)

 

I'm running out of time now but then you can go ahead, iterate through and print out a link which will be something like:

 

echo '<a href="yourpage.php?start=' . $start + 10 . '">next 10 »</a>';

 

I personally prefer a "get next 10 items" link which uses ajax and similar techniques to get the next 10.

 

*disclaimer: above isn't debugged!

Link to comment
Share on other sites

Thanks,

 

Although im having problems with the query;

 

define('ITEMS_PER_PAGE', 10);

$start = (isset($_GET['start']) && is_numeric($_GET['start'])) ? $_GET['start'] : 0;

    $result = mysql_query("SELECT * FROM berichten ORDER BY id DESC LIMIT $start,.ITEMS_PER_PAGE; + 1")

 

This prints;

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.ITEMS_PER_PAGE; + 1' at line 1

 

I also tried ".ITEMS_PER_PAGE; + 1 and \".ITEMS_PER_PAGE; + 1 and '.ITEMS_PER_PAGE; + 1 but cant get it to work.

 

Edit; Leaving the ; away gives the same.

 

Thanks!

Link to comment
Share on other sites

<?php

$find = mysql_real_escape_string($_GET['find']);
$search = mysql_real_escape_string($_GET['search']);

$pieces = explode(" ", $find);

define('ITEMS_PER_PAGE', 10);

$start = (isset($_GET['start']) && is_numeric($_GET['start'])) ? $_GET['start'] : 0;

if(!empty($search))
{
    $result = mysql_query("SELECT * FROM berichten WHERE onderwerp LIKE '$search' ORDER BY id DESC")
    or die(mysql_error());
}
elseif(!empty($pieces[0]) && !empty($pieces[1]))
{
   $result = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' OR bericht LIKE '%$pieces[1]%' ORDER BY id DESC")
   or die(mysql_error());
}
elseif(!empty($pieces[0]) && empty($pieces[1]))
{
   $result = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' ORDER BY id DESC")
   or die(mysql_error());
}
else
{
$sql = "SELECT * FROM berichten ORDER BY id DESC LIMIT $start, " . ITEMS_PER_PAGE + 1;
echo $sql;
$result = mysql_query($sql);
}

    include("includes/rating_functions.php");

    $numofrows = @mysql_num_rows($result);
    for($i = 0; $i < $numofrows; $i++)
    {
    $row = mysql_fetch_array( $result );

    $id = $row['id'];
    $message = $row['bericht'];
    $onderwerp = $row['onderwerp'];
    $titel = $row['titel'];

$titel2 = eregi_replace(' ', '-', $titel);
$titel2 = strtolower($titel2);

	$onderwerp2 = strtolower($onderwerp);

$opvragen = "SELECT COUNT(*) AS aantal FROM antwoorden WHERE postid = $id";
$aantal2 = (mysql_query($opvragen));
$getal = mysql_result($aantal2, 'aantal');

           if($i % 2)
                   {
                   $color = "brown";
           $hexcolor = "#e8d6b6";
                   }
           else
                   {
                   $color = "gray";
           $hexcolor = "#f4f4f4";
                   }
       echo "<table border=\"0\" bordercolor=\"#FF0000\" cellpadding=\"0\" cellspacing=\"0\" width=\"578\">";
       echo "<tr class=\"contentbox_top_".$color."\">";
       echo "<td height=\"54\"><b><a href=\"../".$titel2."-".$id.".html\">$titel</a></b> door Anoniem".$id." in <a href=\"../onderwerp-".$onderwerp2.".html\">".$onderwerp."</a> op ".$row['datum']."</td>";
       echo "</tr>";
       echo "<tr BGCOLOR=\"".$hexcolor."\">";
       echo "<td>";
echo $message;
       echo "<br><br>";
       echo "<a href=\"javascript:popup('$id')\">Vertel een vriend(in) hierover</a> - ";
       echo "<a href=\"../".$titel2."-".$id.".html\">Geef commentaar ($getal)</a><br><br>";
       echo pullRating($id,true,true,true,NULL);
       echo "</td>";
       echo "</tr>";
       echo "<tr class=\"contentbox_bottom_".$color."\">";
       echo "<td height=\"17\"></td>";
       echo "</tr>";
       echo "</table>";

    }

    echo "<script type=\"text/javascript\">";
    echo "function popup(id){";
    echo "window.open('tell_a_friend.php?nummer=' + id +'','tellafriend_script','scrollbars=1,statusbar=1,resizable=1,width=400,height=510');}";
    echo "</script>";


    ?>

Link to comment
Share on other sites

You really need to re-factor that code. All query results should be checked before attempting to use them. The general syntax would be....

 

$sql = "your query";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    // it is safe to use $result in here.
  } else {
    // no results where found
  }
} else {
  // an error occurred, handle it.
}

 

You could likely re-factor allot of those queries into JOINs as well, making your code allot more efficient. As for this....

 

$sql = "SELECT * FROM berichten ORDER BY id DESC LIMIT $start, " . ITEMS_PER_PAGE + 1;
echo $sql;

 

echo'ing 1. Not possible.

Link to comment
Share on other sites

BTW, i was thinking about what you said concerning validating all query results, but i'm not kinda sure how to do that.

 

Let's say i have this code;

 

    $result = mysql_query("SELECT * FROM berichten ORDER BY id DESC")
    or die(mysql_error());

    $numofrows = @mysql_num_rows($result);
    for($i = 0; $i < $numofrows; $i++)
    {
    $row = mysql_fetch_array( $result );

    $id = $row['id'];
    $message = $row['bericht'];
    $onderwerp = $row['onderwerp'];
    $titel = $row['titel'];

    }

 

How would i add the if statement then to check it?

 

Like this?

 

    $result = mysql_query("SELECT * FROM berichten ORDER BY id DESC") or die(mysql_error());
if ($row = mysql_query($result)) {
  if (mysql_num_rows($row)) {

    $id = $row['id'];
    $message = $row['bericht'];
    $onderwerp = $row['onderwerp'];
    $titel = $row['titel'];

  } else {
    // no results where found
  }
} else {
  // an error occurred, handle it.
}

 

Thanks

Link to comment
Share on other sites

Apart from that, thanks to a friend i got it working (via a different way though).

 

    $result2 = mysql_query("SELECT * FROM berichten ORDER BY id DESC")
    or die(mysql_error());
    $totaalrecords = mysql_num_rows($result2);

$ITEMS_PER_PAGE = "3";

$start = (isset($_GET['start']) && is_numeric($_GET['start'])) ? $_GET['start'] : 0;

if ( $start+$ITEMS_PER_PAGE<$totaalrecords ) {
echo "<a href=\"index.php?start=$link\">next 3 »</a>";
}

$nummer = "1";
for ( $counter = 0; $counter <= $totaalrecords; $counter += $ITEMS_PER_PAGE ) {
echo "<a href=\"index.php?start=$counter\">pagina $nummer</a> ";
$nummer = $nummer +1;
} 

 

This outputs (i have 7 records at the moment)

 

index.php?start=0

next 3 »

page 1 page 2 page 3

 

index.php?start=3

next 3 »

page 1 page 2 page 3

 

index.php?start=6

page 1 page 2 page 3

 

So that's fine. Only thing i want is, instead of page 1 till 1500 (in the far future), something like this;

 

1 - 2 - 3 ... 120 - 121 - 122

 

When you are on page 15, it will show 12 - 13 - 14 ... 120 - 121 - 122.

 

Can anyone help me with that?

 

Thanks!

Link to comment
Share on other sites

Can't edit my message?

 

Here is my current code, made some changes:

 

 <?php include 'config/connect.php';

$ITEMS_PER_PAGE = "2";

$start = (isset($_GET['start']) && is_numeric($_GET['start'])) ? $_GET['start'] : 0;

$find = mysql_real_escape_string($_GET['find']);
$search = mysql_real_escape_string($_GET['search']);

$pieces = explode(" ", $find);

if(!empty($search))
{
    $totaal = mysql_query("SELECT * FROM berichten WHERE onderwerp LIKE '$search' ORDER BY id DESC") 
    or die(mysql_error());
    $result = mysql_query("SELECT * FROM berichten WHERE onderwerp LIKE '$search' ORDER BY id DESC LIMIT $start,$ITEMS_PER_PAGE")
    or die(mysql_error());
    $totaalrecords = mysql_num_rows($totaal);
}
elseif(!empty($pieces[0]) && !empty($pieces[1]))
{
    $totaal = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' OR bericht LIKE '%$pieces[1]%' ORDER BY id DESC")
    or die(mysql_error());
    $result = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' OR bericht LIKE '%$pieces[1]%' ORDER BY id DESC LIMIT $start,$ITEMS_PER_PAGE")
    or die(mysql_error());
    $totaalrecords = mysql_num_rows($totaal);
}
elseif(!empty($pieces[0]) && empty($pieces[1]))
{
    $totaal = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' ORDER BY id DESC")
    or die(mysql_error());
    $result = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' ORDER BY id DESC LIMIT $start,$ITEMS_PER_PAGE")
    or die(mysql_error());
    $totaalrecords = mysql_num_rows($totaal);
}
else
{
    $result = mysql_query("SELECT * FROM berichten ORDER BY id DESC LIMIT $start,$ITEMS_PER_PAGE")
    or die(mysql_error());
    $result2 = mysql_query("SELECT * FROM berichten ORDER BY id DESC")
    or die(mysql_error());
    $totaalrecords = mysql_num_rows($result2);
}

echo "<br><a href=\"plaats.html\"><img src=\"images/melden_knop.jpg\" border=\"0\" /></a><br><br>";

$link = $start + $ITEMS_PER_PAGE;

if(!empty($search))
{
   $keuze = "onderwerp-$search-pagina";
}
elseif(!empty($pieces[0]))
{
   $keuze = "zoeken-$find-pagina";
}
else
{
   $keuze = "pagina";
}

if ( $start+$ITEMS_PER_PAGE<$totaalrecords ) {
echo "<a href=\"$keuze-$link.html\">next $ITEMS_PER_PAGE »</a>";
}

echo "<br>";

$nummer = "1";
for ( $counter = 0; $counter < $totaalrecords; $counter += $ITEMS_PER_PAGE ) {
echo "<a href=\"$keuze-$counter.html\">pagina $nummer</a> ";
$nummer = $nummer +1;
}

    include("includes/rating_functions.php");

    $numofrows = @mysql_num_rows($result);
    for($i = 0; $i < $numofrows; $i++)
    {
    $row = mysql_fetch_array( $result );

    $id = $row['id'];
    $message = $row['bericht'];
    $onderwerp = $row['onderwerp'];
    $titel = $row['titel'];

$titel2 = eregi_replace(' ', '-', $titel);
$titel2 = strtolower($titel2);

	$onderwerp2 = strtolower($onderwerp);

$opvragen = "SELECT COUNT(*) AS aantal FROM antwoorden WHERE postid = $id";
$aantal2 = (mysql_query($opvragen));
$getal = mysql_result($aantal2, 'aantal');

           if($i % 2)
                   {
                   $color = "brown";
           $hexcolor = "#e8d6b6";
                   }
           else
                   {
                   $color = "gray";
           $hexcolor = "#f4f4f4";
                   }
       echo "<table border=\"0\" bordercolor=\"#FF0000\" cellpadding=\"0\" cellspacing=\"0\" width=\"578\">";
       echo "<tr class=\"contentbox_top_".$color."\">";
       echo "<td height=\"54\"><b><a href=\"../".$titel2."-".$id.".html\">$titel</a></b> door Anoniem".$id." in <a href=\"../onderwerp-".$onderwerp2.".html\">".$onderwerp."</a> op ".$row['datum']."</td>";
       echo "</tr>";
       echo "<tr BGCOLOR=\"".$hexcolor."\">";
       echo "<td>";
echo $message;
       echo "<br><br>";
       echo "<a href=\"javascript:popup('$id')\">Vertel een vriend(in) hierover</a> - ";
       echo "<a href=\"../".$titel2."-".$id.".html\">Geef commentaar ($getal)</a><br><br>";
       echo pullRating($id,true,true,true,NULL);
       echo "</td>";
       echo "</tr>";
       echo "<tr class=\"contentbox_bottom_".$color."\">";
       echo "<td height=\"17\"></td>";
       echo "</tr>";
       echo "</table>";

    }

    echo "<script type=\"text/javascript\">";
    echo "function popup(id){";
    echo "window.open('tell_a_friend.php?nummer=' + id +'','tellafriend_script','scrollbars=1,statusbar=1,resizable=1,width=400,height=510');}";
    echo "</script>";


    ?> 

Link to comment
Share on other sites

Can anyone help please? I made the code a bit more neat, just don't know how to do the trick when there are many pages (see some posts higher).

 

<?php include 'config/connect.php';

$ITEMS_PER_PAGE = "2";

$start = (isset($_GET['start']) && is_numeric($_GET['start'])) ? $_GET['start'] : 0;

$find = mysql_real_escape_string($_GET['find']);
$search = mysql_real_escape_string($_GET['search']);

$pieces = explode(" ", $find);

if(!empty($search))
{
    $totaal = mysql_query("SELECT * FROM berichten WHERE onderwerp LIKE '$search' ORDER BY id DESC") 
    or die(mysql_error());
    $result = mysql_query("SELECT * FROM berichten WHERE onderwerp LIKE '$search' ORDER BY id DESC LIMIT $start,$ITEMS_PER_PAGE")
    or die(mysql_error());
    $totaalrecords = mysql_num_rows($totaal);
}
elseif(!empty($pieces[0]) && !empty($pieces[1]))
{
    $totaal = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' OR bericht LIKE '%$pieces[1]%' ORDER BY id DESC")
    or die(mysql_error());
    $result = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' OR bericht LIKE '%$pieces[1]%' ORDER BY id DESC LIMIT $start,$ITEMS_PER_PAGE")
    or die(mysql_error());
    $totaalrecords = mysql_num_rows($totaal);
}
elseif(!empty($pieces[0]) && empty($pieces[1]))
{
    $totaal = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' ORDER BY id DESC")
    or die(mysql_error());
    $result = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' ORDER BY id DESC LIMIT $start,$ITEMS_PER_PAGE")
    or die(mysql_error());
    $totaalrecords = mysql_num_rows($totaal);
}
else
{
    $result = mysql_query("SELECT * FROM berichten ORDER BY id DESC LIMIT $start,$ITEMS_PER_PAGE")
    or die(mysql_error());
    $result2 = mysql_query("SELECT * FROM berichten ORDER BY id DESC")
    or die(mysql_error());
    $totaalrecords = mysql_num_rows($result2);
}

echo "<br /><a href=\"plaats.html\"><img src=\"images/melden_knop.jpg\" border=\"0\" alt=\"Plaats een verhaal\" /></a><br /><br />";

$link = $start + $ITEMS_PER_PAGE;

if(!empty($search))
{
   $keuze = "onderwerp-$search-pagina";
}
elseif(!empty($pieces[0]))
{
   $keuze = "zoeken-$find-pagina";
}
else
{
   $keuze = "pagina";
}

    include("includes/rating_functions.php");

    $numofrows = @mysql_num_rows($result);
    for($i = 0; $i < $numofrows; $i++)
    {
    $row = mysql_fetch_array( $result );

    $id = $row['id'];
    $message = $row['bericht'];
    $onderwerp = $row['onderwerp'];
    $titel = $row['titel'];

    $date_entered = date("d/m/Y", strtotime($row[datum]));

$titel2 = eregi_replace(' ', '-', $titel);
$titel2 = strtolower($titel2);

	$onderwerp2 = strtolower($onderwerp);

$opvragen = "SELECT COUNT(*) AS aantal FROM antwoorden WHERE postid = $id";
$aantal2 = (mysql_query($opvragen));
$getal = mysql_result($aantal2, 'aantal');

           if($i % 2)
                   {
                   $color = "brown";
           $hexcolor = "#e8d6b6";
                   }
           else
                   {
                   $color = "gray";
           $hexcolor = "#f4f4f4";
                   }

       echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"578\">";
       echo "<tr class=\"contentbox_top_".$color."\">";
       echo "<td height=\"54\"><strong><a href=\"../".$titel2."-".$id.".html\">$titel</a></strong> door Anoniem".$id." in <a href=\"../onderwerp-".$onderwerp2.".html\">".$onderwerp."</a> op ".$date_entered."</td>";
       echo "</tr>";
       echo "<tr bgcolor=\"".$hexcolor."\">";
       echo "<td>";
echo $message;
       echo "<br /><br />";
       echo "<a href=\"javascript:popup('$id')\">Vertel een vriend(in) hierover</a> - ";
       echo "<a href=\"../".$titel2."-".$id.".html\">Geef commentaar ($getal)</a><br /><br />";
       echo pullRating($id,true,true,true,NULL);
       echo "</td>";
       echo "</tr>";
       echo "<tr class=\"contentbox_bottom_".$color."\">";
       echo "<td height=\"17\"></td>";
       echo "</tr>";
       echo "</table>";

    }

    echo "<script type=\"text/javascript\">";
    echo "function popup(id){";
    echo "window.open('tell_a_friend.php?nummer=' + id +'','tellafriend_script','scrollbars=1,statusbar=1,resizable=1,width=400,height=510');}";
    echo "</script>";

if ( $start+$ITEMS_PER_PAGE<$totaalrecords ) {
echo "<a href=\"$keuze-$link.html\">Volgende pagina »</a>";
}

echo "<br />";

$nummer = "1";
for ( $counter = 0; $counter < $totaalrecords; $counter += $ITEMS_PER_PAGE ) {
echo "<a href=\"$keuze-$counter.html\">$nummer</a> ";
$nummer = $nummer +1;
}

    ?>

Link to comment
Share on other sites

  • 2 weeks later...

I changed the entire code. Made use of: http://www.phpeasystep.com/phptu/29.html

 

Here it is if anyone is interested:

 

<?php $valid_ips = array('194.171.252.101','130.138.227.10','88.159.185.149');
if (!in_array($_SERVER['REMOTE_ADDR'],$valid_ips)) {
    echo "<b>Binnenkort online!</b>";
    exit();
}  ?>

<?php include 'header.php'; ?>

<div id="content">
<div id="contentleft">

<?php

$tbl_name="berichten";

$adjacents = 3;

$targetpage = "index.php";
$limit = 2;
$page = $_GET['page'];

if($page)
$start = ($page - 1) * $limit;
else
$start = 0;

$find = mysql_real_escape_string($_GET['find']);
$search = mysql_real_escape_string($_GET['search']);

$pieces = explode(" ", $find);

if(!empty($search))
{
    $result = mysql_query("SELECT * FROM berichten WHERE onderwerp LIKE '$search' ORDER BY id DESC LIMIT $start, $limit") 
    or die(mysql_error());

$query = mysql_query("SELECT COUNT(*) as num FROM $tbl_name WHERE onderwerp LIKE '$search'")
    	or die(mysql_error());
$total_pages = mysql_fetch_array($query);
$total_pages = $total_pages[num];

}
elseif(!empty($pieces[0]) && !empty($pieces[1]))
{
    $result = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' OR bericht LIKE '%$pieces[1]%' ORDER BY id DESC LIMIT $start, $limit")
    or die(mysql_error());

$query = mysql_query("SELECT COUNT(*) as num FROM $tbl_name WHERE onderwerp LIKE '%$pieces[0]%' OR bericht LIKE '%$pieces[1]%'")
    	or die(mysql_error());
$total_pages = mysql_fetch_array($query);
$total_pages = $total_pages[num];
}
elseif(!empty($pieces[0]) && empty($pieces[1]))
{
    $result = mysql_query("SELECT * FROM berichten WHERE bericht LIKE '%$pieces[0]%' ORDER BY id DESC LIMIT $start, $limit")
    or die(mysql_error());

$query = mysql_query("SELECT COUNT(*) as num FROM $tbl_name WHERE bericht LIKE '%$pieces[0]%'")
    	or die(mysql_error());
$total_pages = mysql_fetch_array($query);
$total_pages = $total_pages[num];

}
else
{
    $result = mysql_query("SELECT * FROM berichten ORDER BY id DESC LIMIT $start, $limit")
    or die(mysql_error());

$query = mysql_query("SELECT COUNT(*) as num FROM $tbl_name")
    	or die(mysql_error());
$total_pages = mysql_fetch_array($query);
$total_pages = $total_pages[num];

}

if ($page == 0) $page = 1;
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$lpm1 = $lastpage - 1;

echo "<br /><a href=\"plaats.html\"><img src=\"images/melden_knop.jpg\" border=\"0\" alt=\"Plaats een verhaal\" /></a><br /><br />";

?>

<?php

if(!empty($search))
{
   $keuze = "onderwerp-$search-pagina";
}
elseif(!empty($pieces[0]))
{
   $keuze = "zoeken-$find-pagina";
}
else
{
   $keuze = "pagina";
}

$pagination = "";
if($lastpage > 1)
{	
	$pagination .= "<div class=\"pagination\">";
	if ($page > 1) 
		$pagination.= "<a href=\"$keuze-$prev.html\">« vorige</a>";
	else
		$pagination.= "<span class=\"disabled\">« vorige</span>";	

	if ($lastpage < 7 + ($adjacents * 2))
	{	
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
			if ($counter == $page)
				$pagination.= "<span class=\"current\">$counter</span>";
			else
				$pagination.= "<a href=\"$keuze-$counter.html\">$counter</a>";					
		}
	}
	elseif($lastpage > 5 + ($adjacents * 2))
	{
		if($page < 1 + ($adjacents * 2))		
		{
			for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$keuze-$counter.html\">$counter</a>";					
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$keuze-$lpm1.html\">$lpm1</a>";
			$pagination.= "<a href=\"$keuze-$lastpage.html\">$lastpage</a>";		
		}
		elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
		{
			$pagination.= "<a href=\"$keuze-1.html\">1</a>";
			$pagination.= "<a href=\"$keuze-2.html\">2</a>";
			$pagination.= "...";
			for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$keuze-$counter.html\">$counter</a>";					
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$keuze-$lpm1.html\">$lpm1</a>";
			$pagination.= "<a href=\"$keuze-$lastpage.html\">$lastpage</a>";		
		}
		else
		{
			$pagination.= "<a href=\"$keuze-1.html\">1</a>";
			$pagination.= "<a href=\"$keuze-2.html\">2</a>";
			$pagination.= "...";
			for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$keuze-$counter.html\">$counter</a>";				
			}
		}
	}

	if ($page < $counter - 1) 
		$pagination.= "<a href=\"$keuze-$next.html\">volgende »</a>";
	else
		$pagination.= "<span class=\"disabled\">volgende »</span>";
	$pagination.= "</div>\n";		
}

?>

<?php

    include("includes/rating_functions.php");

    $numofrows = @mysql_num_rows($result);
    for($i = 0; $i < $numofrows; $i++)
    {
    $row = mysql_fetch_array( $result );

    $id = $row['id'];
    $message = $row['bericht'];
    $onderwerp = $row['onderwerp'];
    $titel = $row['titel'];

    $date_entered = date("d/m/Y", strtotime($row[datum]));

$titel2 = eregi_replace(' ', '-', $titel);
$titel2 = strtolower($titel2);

	$onderwerp2 = strtolower($onderwerp);

$opvragen = "SELECT COUNT(*) AS aantal FROM antwoorden WHERE postid = $id";
$aantal2 = (mysql_query($opvragen));
$getal = mysql_result($aantal2, 'aantal');

           if($i % 2)
                   {
                   $color = "brown";
           $hexcolor = "#e8d6b6";
                   }
           else
                   {
                   $color = "gray";
           $hexcolor = "#f4f4f4";
                   }

       echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"578\">";
       echo "<tr class=\"contentbox_top_".$color."\">";
       echo "<td height=\"54\"><strong><a href=\"../".$titel2."-".$id.".html\">$titel</a></strong> door Anoniem".$id." in <a href=\"../onderwerp-".$onderwerp2.".html\">".$onderwerp."</a> op ".$date_entered."</td>";
       echo "</tr>";
       echo "<tr bgcolor=\"".$hexcolor."\">";
       echo "<td>";
echo $message;
       echo "<br /><br />";
       echo "<a href=\"vertel-$id.html\" target=\"arbitrade\" onclick=\"return !window.open(this.href, this.target, 'scrollbars,resizable,width=415,height=510');\">Vertel een vriend(in) hierover</a> - ";
       echo "<a href=\"../".$titel2."-".$id.".html\">Geef commentaar ($getal)</a><br /><br />";
       echo pullRating($id,true,true,true,NULL);
       echo "</td>";
       echo "</tr>";
       echo "<tr class=\"contentbox_bottom_".$color."\">";
       echo "<td height=\"17\"></td>";
       echo "</tr>";
       echo "</table>";

    }

    echo "<script type=\"text/javascript\">";
    echo "function popup(id){";
    echo "window.open('tell_a_friend.php?nummer=' + id +'','tellafriend_script','scrollbars=1,statusbar=1,resizable=1,width=400,height=510');}";
    echo "</script>";

?>

<?=$pagination?>

<br />

</div><!-- Closing contentleft -->

<?php include 'menu.php'; ?>

<?php include 'footer.php'; ?>

</div>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.