Sidefunktion - virker ikk optimalt
// http://www.eksperten.dk/spm/830684...
Min side-funktion virker ikke helt optimalt..
Jeg vil have den til at lave sider, udfra hvor mange spil der findes i databasen under en specifik kategori.
Min kode:
<body link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
<table border="0" width="495" height="56">
<tr>
<?
include "config/database.php";
$kategori = $_GET["valg"];
$offset = (isset($_GET['offset']) && is_numeric($_GET['offset']) && $_GET['offset'] >= 0) ? intval($_GET['offset']) : 0;
$antal = mysql_result(mysql_query("select COUNT(id) from spil WHERE kategori = '$kategori'"),0);
$page = 5;
if($offset > 0){
$prev = $offset - $page;
echo '<a href="?side=spil_kat&valg='.$kategori.'&offset='.$prev.'">Forrige</a>';
}else{
echo 'Forrige';
}
echo ' - ';
if(($offset+$page) < $antal){
$next = $offset + $page;
echo '<a href="?side=spil_kat&valg='.$kategori.'&offset='.$next.'">Næste</a>';
}else{
echo 'Næste';
}
echo '<hr />';
$kategori = $_GET["valg"];
$hent = mysql_query("SELECT * FROM spil WHERE kategori = '$kategori' ORDER BY id");
while($vis = mysql_fetch_array($hent)) {
?><td width="100" rowspan="3" height="1"><a target="_blank" href="play.php?id=<? echo $vis[id]; ?>"><img src="grafik/spil/<? print $vis["kategori"]; ?>/<? print $vis["image"]; ?>" width="100" height="100" border="0" style="filter:alpha(opacity=70)"></a></td>
<td height="1"><a target="_blank" href="play.php?id=<? echo $vis[id]; ?>"><strong><? print $vis["navn"]; ?></strong></a></td>
<td height="1"><div align="right"><font color="#000000">
<? print $vis["klik"]; ?>
hits</font></div></td>
</tr>
<tr>
<td height="43" colspan="2"><a target="_blank" href="play.php?id=<? echo $vis[id]; ?>"><? print $vis["beskrivelse"]; ?></a></td>
</tr>
<tr>
<td width="283" height="1"><a target="_blank" href="play.php?id=<? echo $vis[id]; ?>"><font color="#CCCCCC"><?=substr($vis[link],0,50);?></font></a></td>
<td width="95" height="1"><div align="right"><a href="?side=spil_kat&id=<? echo $vis[id]; ?>&navn=<? echo $vis[navn]; ?>&favorit=ja">- favorit</a></div></td>
</tr>
<tr>
<td height="1"><hr color="#EAEAEA" size="1"/></td>
<td height="1"><hr color="#EAEAEA" size="1"/></td>
<td height="1"><hr color="#EAEAEA" size="1"/></td>
</tr> <?
}
?>
</table>