Jump to content

Variable Operations


smithmr8

Recommended Posts

Hi,

I'm trying to get a page system together for displaying items from a DB.

 

$page = $_GET['page'];
$upper = ($page - 1)*50;
$lower = $page * 50;
echo "Page:".$page."<br />";
echo "Lower:".$lower."<br />";
echo "Upper:".$upper."<br />";

 

The above is the code I am using.

 

I am going to a page, ie. products.php?page=1

This gives the page variable the value of 1, which will display when echo'd.

However, if I try to perform any operations on it, it displays nothing.

 

$lower needs to be equal to the value of $page - 1 * 50

$upper needs to be equal to the value of $page * 50

 

But I cant get it to do this.

 

Any ideas ?

Link to comment
https://forums.phpfreaks.com/topic/207075-variable-operations/
Share on other sites

I would add an isset() and is_numerical on that page variable to make a default value:

$page = (isset($_GET['page']) && is_numerical($_GET['page']))? $_GET['page'] : 1;
$upper = ($page - 1)*50;
$lower = $page * 50;
echo "Page:".$page."<br />";
echo "Lower:".$lower."<br />";
echo "Upper:".$upper."<br />";

 

-cb-

Link to comment
https://forums.phpfreaks.com/topic/207075-variable-operations/#findComment-1082765
Share on other sites

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.