PHP expert |
|
ik ben een noob op het gebied van functies, maar wilde het eens proberen , wat is er fout aan deze functie
<?php
function navigation($table,$map,$file,$rowsPerPage,$pageNum) {
$result = mysql_query("SELECT COUNT(id) AS numrows FROM ".$table."") or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$nav = '';
for($page = 1; $page <= $maxPage; $page++) {
if ($page == $pageNum) {
$nav .= " Page: <b>$page</b>";
}else{
$nav .= "<a href=\"?page='".$map."'/'".$file."'&p=$page\">$page</a> ";
}
}
if ($pageNum > 1) {
$page = $pageNum - 1;
$prev = "<a href=\"?page='".$map."'/'".$file."'&p=$page\">[Prev]</a> ";
$first = "<a href=\"?page='".$map."'/'".$file."'&p=1\">[First Page]</a> ";
}else{
$prev = ' ';
$first = ' ';
}
if ($pageNum < $maxPage) {
$page = $pageNum + 1;
$next = "<a href=\"?page='".$map."'/'".$file."'&p=$page\">[Next]</a> ";
$last = "<a href=\"?page='".$map."'/'".$file."'&p=$maxPage\">[Last Page]</a> ";
}else{
$next = ' ';
$last = ' ';
}
$navi = $first . $prev . $nav . $next . $last;
return $navi;
}
?>
<?php function navigation($table,$map,$file,$rowsPerPage,$pageNum) { $numrows = $row['numrows']; $maxPage = ceil($numrows/$rowsPerPage); $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " Page: <b>$page</b>"; }else{ $nav .= "<a href=\"?page='".$map."'/'".$file."'&p=$page\">$page</a> "; } } if ($pageNum > 1) { $page = $pageNum - 1; $prev = "<a href=\"?page='".$map."'/'".$file."'&p=$page\">[Prev]</a> "; $first = "<a href=\"?page='".$map."'/'".$file."'&p=1\">[First Page]</a> "; }else{ $prev = ' '; $first = ' '; } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = "<a href=\"?page='".$map."'/'".$file."'&p=$page\">[Next]</a> "; $last = "<a href=\"?page='".$map."'/'".$file."'&p=$maxPage\">[Last Page]</a> "; }else{ $next = ' '; $last = ' '; } $navi = $first . $prev . $nav . $next . $last; return $navi; } ?>
sorry voor de grootte, maar het was niet anders
nu doe ik in mijn news.php dit
<?php
navigation(news,news,news,10,1);
?>
<?php navigation(news,news,news,10,1); ?>
alleen er word nix weergegeven
onderstaande code is correct, was echo vergete (probleem is opgelost, maar zet de oplossing erbij
<?php
echo navigation(news,news,news,10,1);
?>
<?php echo navigation (news ,news ,news ,10,1); ?>
|