Innovati0n Posted December 20, 2010 Share Posted December 20, 2010 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. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10, 10' at line 1 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. Link to comment https://forums.phpfreaks.com/topic/222207-mysqlphp-pagination-errors/ Share on other sites More sharing options...
BlueSkyIS Posted December 20, 2010 Share Posted December 20, 2010 take a look at your SQL to see what's wrong. i always do this with my queries: $sql = "SELECT * FROM $table ORDER BY id ASC"; $result = mysql_query($sql) or die (mysql_error() . " IN $sql); but i don't think that error is coming from the code you posted. Link to comment https://forums.phpfreaks.com/topic/222207-mysqlphp-pagination-errors/#findComment-1149518 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.