I’m new to PHP so I’m just to get to grips with a few things. It's giving me the error shown below.
What I'm trying to make it so is give me some text when nothing is in the MySQL table, such as "No articles just yet". I also don't want any of the buttons to show.
<?php
$table = "news";
$prows = 10;
$spread = 6;
$page = $_GET['p'];
$query = mysql_query("SELECT * FROM $table ORDER BY id ASC");
$rows = mysql_num_rows($query);
$lastp = ceil($rows / $prows);
// ###
if (!isset($page)) {
$page = 1;
}
if ($page < 1) {
$page = 1;
}
if ($page > $lastp) {
$page = $lastp;
}
// ###
$page = isset($_GET['p']) ? $_GET['p'] : 1;
$pn = ($page * $prows) - $prows;
// ALL MY CODE IS HERE!!!!!!!!!!!!
}
echo("\t<div class=\"pagination_wrapper\">\n");
echo("\t <div class=\"pagination\">");
// ###
if ($page == 1) {
echo("");
} else {
echo("<a href='index.php?p=1' class=\"pagination\">First</a>");
}
// ###
if ($page > 1) {
$prev = $page - 1;
echo("<a href='index.php?p=$prev' class=\"pagination\">Previous</a>");
} else {
echo("");
}
// ###
$min = $page - $spread;
$max = $page + $spread;
if ($min < 1) {
$dif = 1 - $min;
$min = 1;
$max = $max + $dif;
}
if ($max > $lastp) {
$dif = $lastp - $max;
$max = $lastp;
$min = $min + $dif;
}
if ($min < 1) {
$min = 1;
}
// ###
for ($i = $min; $i <= $max; $i++) {
if ($i == $page) {
echo("<a href='index.php?p=$i' class=\"pagination selected\">$i</a>");
} else {
echo("<a href='index.php?p=$i' class=\"pagination\">$i</a>");
}
}
// ###
if ($page < $lastp) {
$next = $page + 1;
echo("<a href='index.php?p=$next' class=\"pagination\">Next</a>");
} else {
echo("");
}
// ###
if ($page == $lastp) {
echo("");
} else {
echo("<a href='index.php?p=$lastp' class=\"pagination\">Last</a>");
}
echo("</div>\n");
echo("\t</div>\n");
// ###
?>
If you could help then it would be amazing, thank you.