Help to edit code for pages

hi

i have this code to pages it’s work good but the problems

when anyone insert in url untrue (number) or (-+) or letter

ex: art.php?go=art&id=-34gf+223

give him error page

i want when insert untrue direct back to first page

also he is showin all number of page like tihs 123456789 <to end number

need him like that 12345…next

if can some one edit code for me

if (!($limit)){
$limit = 8;} // number at one page
if (!($page)){
$page = 0;}
$numresults = mysql_query("SELECT * FROM t WHERE ca ORDER BY id DESC limit ");
$qry = mysql_num_rows($numresults);

$pages = intval($qry/$limit);
if ($qry%$limit) {
$pages++;}
$current = ($page/$limit) + 1;
if (($pages < 1) || ($pages == 0)) {
$total = 1;}
else {
$total = $pages;}
$first = $page + 1;
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;}
else{
$last = $qry;}
 
if ($page != 0) {
$back_page = $page - $limit;
echo("<a href=\\"/art/cat-$catid-$back_page.htm\\"><font color=red>[prev]</font></a> \
");}
for ($i=1; $i <= $pages; $i++)
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b> \
");}
else{
echo("<a href=\\"/art/cat-$catid-$ppage.htm\\">[$i]</a> \
");}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) {
$next_page = $page + $limit;
echo(" <a href=\\"/art/cat-$catid-$next_page.htm\\"><font color=red>[next]</font></a>\
");} 

thanks for help now it’s ok :tup:

if($page==""||$page==0||$page==1||$page>$qry||$page<0) { 
$page = 1; // now use page = 1 = first page of section
$startIndex=0; 
 $endIndex=$limit; 
 } 
 else { 
 $startIndex=($page-1)*($limit); 
 $endIndex=$limit; 
 }

thanks agian =)

if(page fails tests) { // test for isset, numeric, cast to int, page exists, etc
$page = 1; // now use page = 1 = first page of section
}

the big problem at my english :smiley:

ok i will try agian , the code work but i want do some edit.

this is url for section page number 2

art.php?go=art&id=12&page=2

ok it’s go

but try insert with number 2 this (-)

ex-art.php?go=art&id=12&page=2-

give me error page

i want when insert something like that direct back to first page for section

Hi Sajed,

Welcome to the Sitepoint Forums!

I could not be much clear about your problem but you can filter any input from the URL or even from some form elements using some PHP in built functions. So rather than editing your code itself I would suggest you some tips as below:

  • check empty value with empty()
  • check if any variables are set with isset()
  • check if it is a numeric value is_numeric() or see in manual page for other options like is _int(), ctype_digit() etc.
  • or even you can check less than or greater than if they are numbers.

Hope this will help you and you can go ahead with correct way to fix your problem.