0

Im trying to make a pagination to my article page.

the problem is i want it to count the articles WHERE category = 1

ive worked with the script for sometime, but it still just shows a blank page no errors.

any suggestions why it wont work?

<?php
error_reporting(E_ALL); ini_set("display_errors", 1);
$db = mysql_connect("localhost", "root", "");
mysql_select_db("dirts_mysql", $db);
echo "<h1>articles</h1>";
$pr_page = 2;
$number = mysql_result(mysql_query("SELECT COUNT(*) FROM article WHERE category =             1"), 0) or die(mysql_error());
$show_from = (isset($_GET["visfra"]) && is_numeric($_GET["visfra"]) && $_GET["visfra"] < $number) ? $_GET["visfra"] : 0;
$query = mysql_query("SELECT * FROM article ORDER BY id DESC limit $show_from,     $pr_page") or die(mysql_error());
while ($row = mysql_fetch_array($query)) {
    ?>
    <link rel="stylesheet" type="text/css" href="style.css">
    <div id="news">
        <h2><u><? echo $row['name']; ?></u></h2>

        <p>
            <?php echo nl2br($row['description']); ?>...
        </p>
        <br/><br/>
        <a href="vis.php?id=<? print $row['id']; ?>">[...]</a>
    </div>
    <br>
<?php
}
if ($show_from > 0) {
    $back = $show_from - $pr_page;
    echo "<a href='?showfrom=$back'>Forrige</a> ";
}
$page = 1;
for ($start = 0; $number > $start; $start = $start + $pr_page) {
    if ($show_from != $page * $pr_page - $pr_page) {
        echo "<a href='?showfrom=$start'>$page</a> ";
    } else {
        echo $page . " ";
    }
    $page++;
}
if ($show_from < $number - $pr_page) {
    $next = $show_from + $pr_page;
    echo " <a href='?&showfrom=$next'>Næste</a>";
}
?>
Christian
  • 51
  • 1
  • 3
  • 11
  • 4
    First suggestion: Format your code please! – puelo Oct 31 '13 at 10:41
  • 3
    Second suggestion: enable full error reporting. – PeeHaa Oct 31 '13 at 10:42
  • Add at top of your file: error_reporting(E_ALL); and update your question with errors. – Choinek Oct 31 '13 at 10:46
  • 2
    Third suggestion: stop using deprecated functions [`mysql_*`](http://php.net/manual/en/function.mysql-query.php) and stop writing code which introduces [SQL injection vulnerabilities](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – PeeHaa Oct 31 '13 at 10:47

1 Answers1

0

add the following on the top of your code:

error_reporting(E_ALL);
ini_set("display_errors", 1);

On the otherside, I will suggest you to start using function to structure your code. :)

Ulrich Horus
  • 352
  • 3
  • 9