PHP/MySql paging!
Hej,Jeg har lavet en paging funktion, men det virker ikke efter hensigten. Det ser sådan ud, når jeg tester: http://www.designunltd.dk/la-femme/kollektion.php
Jeg vil gerne have 16 records pr. page.
Er der nogen, som vil hjælpe mig?
Jeg har følgende kode på min side:
<?php
//connect to the database - either include a connection variable file
//or type the following lines:
$connect = mysql_connect("xxxxx", "xxxxx", "xxxxx")
or die ("Hey loser, check your server connection.");
mysql_select_db ("xxxxx_shop");
?>
<?php include("produkttyper.php") ?>
<?php
$query = "SELECT * FROM products";
$results = mysql_query($query)
or die(mysql_error());
echo "<table><tr>";
if (!isset($_GET[page])) $page = 0;
$antal = 16; // Antal af posts pr side
$total = $page * $antal;
$bla = 16 + 16 * $page;
$sumcount = 1;
$sum = 4;
$i="0";
$result = mysql_query("SELECT * FROM products ORDER BY id DESC LIMIT $total,$antal");
while ($row = mysql_fetch_array($results)) {
extract($row);
echo "<td width=\"100\" height=\"105\" align=\"left\">";
echo "<a href=\"varerbeskrivelse.php?prodid=" . $products_nummer . "\">";
echo "<img src=" . $products_imageurl . " border=\"0\"></a>";
echo "</td>";
if ($sumcount == $sum) {
$sumcount = 0;
echo "</tr><tr>";
}
$sumcount++;
$i++;
}
echo "</tr></table>";
?>
<?
echo"<td width=\"165\" align=\"right\">";
if ($page > 0) {
echo "<a href=\"kollektion.php?page=" . ($page - 1) . "\"><img src=\"images/leftpil.gif\"></a> ";
} else {
echo "<img src=\"images/leftpil.gif\">";
}
echo "</td>";
echo "<td width=\"5\" align=\"right\"> </td>";
echo "<td align=\"center\" width=\"105\">";
echo "<img src=\"images/blomst%20til%20mellem%20pilene.jpg\" width=\"100\">";
echo "</td>";
echo "<td width=\"5\" align=\"left\"> </td>";
echo "<td width=\"170\" align=\"left\">";
if ($num > $bla) {
echo "<a href=\"kollektion.php?page=" . ($page + 1) . "\"><img src=\"images/rightpil.gif\"></a>";
} else {
echo "<img src=\"images/rightpil.gif\">";
}
echo "</td>";
?>
Min include ser således ud:
<?php
//connect to the database - either include a connection variable file
//or type the following lines:
$connect = mysql_connect("xxxxx", "xxxxx", "xxxxx"
or die ("Hey loser, check your server connection.");
mysql_select_db ("xxxxx_shop");
$query_type = "SELECT * FROM productstype";
$results = mysql_query($query_type)
or die(mysql_error());
?>
<?php
echo "<table><tr><td>";
$sumcount = 1;
$sum = 1;
$i="0";
$result = mysql_query("SELECT * FROM productstype ORDER BY id DESC");
while ($row = mysql_fetch_array($results)) {
extract($row);
echo "<font class=\"undermenu\"><a href=\"kollektion.php?prodid=" . $productstype_name . "\">";
echo "" . $productstype_name . "</a> </font>";
if ($sumcount == $sum) {
$sumcount = 0;
}
$sumcount++;
$i++;
}
echo "</td></tr></table>";
?>
