omardavinci Posted September 13, 2016 Share Posted September 13, 2016 Hi i am trying to do a simple pagination in php but when i try for example go to some page like localhost/page=1 i get this result:The requested URL /www/page=2 was not found on this server. Obviously this is because i did some mistake in the code. I share with members the php and html file for if someone has some suggestion. Thanks in advance: html: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title><?php echo $title; ?></title> <link rel="stylesheet" type="text/css" href="Styles/Stylesheet.css" /> </head> <body> <div id="wrapper"> <div id="banner"> </div> <nav id="navigation"> <ul id="nav"> <li><a href="index.php">Home</a></li> <li><a href="tool.php">Coffee</a></li> <li><a href="manager.php">Shop</a></li> <li><a href="#">About</a></li> </ul> </nav> <div id="content_area"> <?php require_once("tool.php"); foreach ($articles as $article): echo $article['id']; endforeach;?></br><?php for($x=1;$x<=$pages;$x++):?> <a href="page=<?php echo $x;?>"><?php echo $x;?></a> <?php endfor;?> </div> <div id="sidebar"> </div> <footer> <p>All rights reserved</p> </footer> </div> </body> </html> php: <?php require_once 'database.php'; $database_connection = database_connect(); $title='hola'; $content='<div>'; //user input $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $perPage = 1; //Positioning $start = ($page > 1) ? ($page * $perPage) - $perPage : 0; $art = $database_connection->query("SELECT id FROM coffee"); //Query $articles = $database_connection->prepare("SELECT id FROM coffee LIMIT 0,5"); $articles->execute(); $articles = $articles->fetchAll(); $resultado = $database_connection->query("SELECT COUNT(*) AS total FROM coffee"); $fila = $resultado->fetch(PDO::FETCH_ASSOC); $total = $fila["total"]; $pages = ceil($total/$perPage); echo $pages; $content .= '<div>'; include 'Template_1.php'; ?> any suggestion, dissapointment is good received Quote Link to comment https://forums.phpfreaks.com/topic/302180-help-with-pagination-in-php/ Share on other sites More sharing options...
ginerjm Posted September 14, 2016 Share Posted September 14, 2016 I'm not even going to look at the code. Your URL is definitely not a URL. Just look at it - where's the domain name? Obviously your(?) code is missing something and I think it is up to you to at least TRY to figure out why you don't have a better looking URL. Not us. Quote Link to comment https://forums.phpfreaks.com/topic/302180-help-with-pagination-in-php/#findComment-1537509 Share on other sites More sharing options...
omardavinci Posted September 14, 2016 Author Share Posted September 14, 2016 ok Quote Link to comment https://forums.phpfreaks.com/topic/302180-help-with-pagination-in-php/#findComment-1537510 Share on other sites More sharing options...
Solution omardavinci Posted September 14, 2016 Author Solution Share Posted September 14, 2016 (edited) solved i am dump i was sending other path Edited September 14, 2016 by omardavinci Quote Link to comment https://forums.phpfreaks.com/topic/302180-help-with-pagination-in-php/#findComment-1537512 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.