Jump to content

subtract 1 from value entered in text field


jmcc

Recommended Posts

This is my code, but because the page number starts with 0 the entered value si different from the page number.

 

I would like to enter the value 10 and go to the page number 10, at this point i enter 10 and go to page 11.

 

The bold part at the bottom is the text filed i want to add one to.

 

Thanks

 

<form id="form1" name="form1"  method="get" action="buyer_map.php?pageNum_seller=<?php $_GET['pageNum_seller'];?>&totalRows_seller=$totalRows_seller">

    <table width="381" border="0" cellpadding="0" cellspacing="0" class="borderless">

      <tr>

        <td height="10" colspan="5"><div align="center"></div></td>

      </tr>

      <tr>

        <td height="10" colspan="5" valign="baseline"><div align="center"> <strong>...</strong>

          <?php

 

$totalPages = $totalPages_seller; // total pages

$currPage = $pageNum_seller + 1; // current page, from GET or whatever

$maxDisplay = 10; // how many to show at once

 

function Paginate($totalPages, $currPage, $maxDisplay = 10) {

 

// Check to see if the current page var is OK

if($currPage>$totalPages) {

$currPage = $totalPages;

}

if($currPage<=0) {

$currPage = 1;

}

// Just to have an even number on either side...

if($maxDisplay%2!=0) {

$maxDisplay--;

}

// Are there more pages than we would display?

if($totalPages < $maxDisplay) {

return range(1,$totalPages);

}

// Would the first element be a negative number or page #0?

if($currPage-($maxDisplay/2) <= 0) {

$range = range(1,$currPage);

$range = array_merge($range, range($currPage+1, $currPage+$maxDisplay-count($range)+1));

return $range;

}

// Would the last element be past the total number of pages?

if($currPage+($maxDisplay/2) > $totalPages) {

$range = range($totalPages, $currPage);

$range = array_merge($range, range($currPage-1, $currPage-$maxDisplay+count($range)-1));

return array_reverse($range);

}

// Otherwise, just add half the max display on either side

return range($currPage-($maxDisplay/2), $currPage+($maxDisplay/2));

}

 

 

// Run through the results:

foreach(Paginate($totalPages, $currPage, 10) as $pageNumber) {

if($pageNumber == $currPage) {

// just show what page we're on:

echo '<u>'.$currPage.'</u>';

} else {

$pageNumber = $pageNumber - 1;

// normally show a link or whatever... but for simplicity we'll just show the number

?>

          <a href="<?php printf("%s?pageNum_seller=$pageNumber&totalRows_seller=$totalRows_seller", $currentPage, min(0, $pageNum_seller = $pageNumber), $queryString_seller); ?>"><?php echo $pageNumber  +1;?></a>

          <?php

}

 

// add a space between the numbers

echo ' ';

}

 

?>

          <strong>...</strong></div></td>

      </tr>

      <tr>

        <td height="5" colspan="5"><div align="center">

          <div align="right"></div>

        </div>

          <div align="center"></div>

          <div align="center">

            <div align="left"></div>

          </div></td>

      </tr>

      <tr>

        <td><div align="right"><a href="<?php printf("%s?pageNum_seller=%d%s", $currentPage, 0, $queryString_seller); ?>">First Page</a> </div></td>

        <td><div align="right">------</div></td>

        <td width="20"></td>

        <td>------ </td>

        <td><a href="<?php printf("%s?pageNum_seller=%d%s", $currentPage, $totalPages_seller, $queryString_seller); ?>">Last Page </a></td>

      </tr>

      <tr>

        <td height="10" colspan="5"></td>

      </tr>

      <tr>

        <td colspan="5"><div align="center">Go to page

          <input name="pageNum_seller" type="text" id="pageNum_seller" size="4" />

          <label>

            <input type="hidden" name="totalRows_seller" id="totalRows_seller" value="<?php echo $totalRows_seller ?>" />

            <input name="submit2" type="submit" id="submit2" value="GO" />

          </label>

        </div>

          <label> </label>

          <div align="center"></div></td>

      </tr>

    </table>

  </form>

How about removing '+ 1' from this line?

$currPage = $pageNum_seller + 1;      // current page, from GET or whatever

 

 

Please use


tags around your code.

 

BTW: Your script seems to be relying on an unsecure feature called register_globals. You should avoid it if possible.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.